Tuesday, February 26, 2008

Using vipw for Creating A New User

Creating a new user by editing the /etc/passwd file with the vi text editor.
This exercise assists you to verify skills of using vi at the command line interface, while there are other ways to create new Linux users.

[root@ephraim Desktop]# useradd test

[root@ephraim Desktop]# mkdir -p /home/np

[root@ephraim Desktop]# ls /home
nicop np nprasetio test

[root@ephraim Desktop]# cd /etc/skel

[root@ephraim skel]# cp .bash_logout .bash_profile .bashrc /home/np

[root@ephraim skel]# ls -la
total 48
drwxr-xr-x 2 root root 4096 Feb 22 05:17 .
drwxr-xr-x 97 root root 12288 Feb 27 07:56 ..
-rw-r--r-- 1 root root 24 Jan 6 2007 .bash_logout
-rw-r--r-- 1 root root 176 Jan 6 2007 .bash_profile
-rw-r--r-- 1 root root 124 Jan 6 2007 .bashrc

[root@ephraim skel]# vipw
nprasetio:x:500:500:Nico Prasetio:/home/nprasetio:/bin/bash
nicop:x:502:502::/home/nicop:/bin/bash
test:x:504:504::/home/test:/bin/bash

Move your cursor and use x to delete test and change to np, also UID and GID (504) change to 505. Use i for adding or typing new character. Change /home/test to /home/np. After finished type :wq to save. You will have this warning "Would you like to edit /etc/shadow now [y/n]?" type y. Then change the test to np as well in /etc/shadow, otherwise you will get this warning "passwd: Authentication token manipulation error"

Last part ;-)
[root@ephraim skel]# passwd np
Changing password for user np.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

Last check:
[root@ephraim skel]# su - nicop
[nicop@ephraim ~]$

Done. You're successfully demonstrated how to use vi to edit /etc/passwd.