When we use useradd command, it will perform following jobs while creating the user in background,

  1. It adds entrys in  /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow files for the newly created user.
  2. Creates a home directory for the new user.
  3. Sets permissions , and give ownership and group to home directory.
  4. Sets default shell
  5. and puts in everything that is in /etc/skel/ directory
  6. 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)

  1. Username: It is used when user logs in. It should be between 1 and 32 characters in length.
  2. Password: An x character indicates that encrypted password is stored in /etc/shadow file.
  3. 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.
  4. Group ID (GID): The primary group ID (stored in /etc/group file)
  5. 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.
  6. 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 /
  7. 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


LOOK into chmod, chage, chown, groupadd,

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.