Sunday, October 10, 2010

What an useradd command in Linux does?

When you execute an useradd command  (# useradd <username>”), the following happens.

1.       Add the new user entry in the following files: /etc/passwd and /etc/shadow

2.       A group will be created with the same username and it will be updated in the following files: /etc/group and /etc/gshadow.

3.       Home folder for the user will be created (/home/<username>) and the default profile settings will be copied from /etc/skel to it.

# ls -la /etc/skel/
total 56
drwxr-xr-x   3 root root  4096 Aug 16 13:03 .
drwxr-xr-x 111 root root 12288 Oct  6 15:10 ..
-rw-r--r--   1 root root    33 Jan 21  2009 .bash_logout
-rw-r--r--   1 root root   176 Jan 21  2009 .bash_profile
-rw-r--r--   1 root root   124 Jan 21  2009 .bashrc
-rw-r--r--   1 root root   515 May 24  2008 .emacs
drwxr-xr-x   4 root root  4096 Jul 26 18:19 .mozilla
-rw-r--r--   1 root root   658 Sep 21  2009 .zshrc
 #


Please note in the case, if you happen to accidently delete either /etc/passwd or /etc/shadow files, you can restore it from its corresponding backup files (i.e /etc/passwd- ,  /etc/shadow- ) respectively. These files are updated upon the system reboot.  So you can’t expect these files to be having the entries for user accounts which are added after the system reboot.

No comments:

Post a Comment