When we use useradd command, it will perform following jobs while creating the user in background,
- It adds entrys in /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow files for the newly created user.
- Creates a home directory for the new user.
- Sets permissions , and give ownership and group to home directory.
- Sets default shell
- and puts in everything that is in /etc/skel/ directory
- User gets password aging information from /etc/login.defs file [informations like when users password will expire, when will account be deactivated etc]
- /etc/passwd – User account information.
- /etc/shadow – Secure account information.
- /etc/group – Group account information.
- /etc/gshadow – Secure group account information.
- /etc/login.defs – Shadow password suite configuration.
Basic syntax of command is:
useradd [options] username
[root@changeme ~]# useradd ram [root@changeme ~]# passwd ram Changing password for user ram. New password: Retype new password: passwd: all authentication tokens updated successfully.
useradd created a user called ram
passwd command created a password for user ram
now lets check /etc/passwd file
after using useradd command it added abovve line in /etc/passwd file
Generally, passwd file entry looks as follows
shyam:x:502:504:this is shyam :/home/shyam:/bin/bash
(Fig.01: /etc/passwd file format – click to enlarge)
- Username: It is used when user logs in. It should be between 1 and 32 characters in length.
- Password: An x character indicates that encrypted password is stored in /etc/shadow file.
- User ID (UID): Each user must be assigned a user ID (UID). UID 0 (zero) is reserved for root and UIDs 1-99 are reserved for other predefined accounts. Further UID 100-499 are reserved by system for administrative and system accounts/groups.
- Group ID (GID): The primary group ID (stored in /etc/group file)
- User Info: The comment field. It allow you to add extra information about the users such as user’s full name, phone number etc. This field use by finger command.
- Home directory: The absolute path to the directory the user will be in when they log in. If this directory does not exists then users directory becomes /
- Command/shell: The absolute path of a command or shell (/bin/bash). Typically, this is a shell. Please note that it does not have to be a shell.
[root@changeme ~]# useradd -u 509 -g 501 -G hr -d /home/bijansir -m -c "linux teacher" -s /bin/sh bijanid
-u to give custom uid
-g to give gid of already created group, priary group
-G to give name of secondary group , -G admin,hr,db [u can give more group seperated by comma]
-d -m to set home directory
-c to give comments or account info
-s to give shell
-e to give expiry date of account
if the user is already created you can change it by using usermod