Home » 2014 » March » 25 » Create a new user in Linux system: useradd

6:35 PM
Create a new user in Linux system: useradd

useradd - This command is used to create a new user account.


useradd [-D binddn] [-P path] [-c comment] [-d homedir] [-e expire] [-f inactive] [-G group,...] [-g gid] [-m [-k skeldir]] [-o] [-p password] [-u uid] [-r] [-s shell] [--service service] [--help] [--usage] [-v] account DESCRIPTION

useradd creates a new user account using the default values from /etc/default/useradd and the specified on the command line.

Depending on the command line options the new account will be added to the system files or LDAP database, the home directory will be created and the initial default files and directories will be copied. You must have admin rights to add a user.

You must have rw acces to passwd file or else it will say " Cannot lock password file: already locked."

ll /etc/passwd -rw-r--r-- 1 root root 21178 2014-03-25 13:04 /etc/passwd

The account name must begin with an alphabetic character and the rest of the string should be from the POSIX portable character class ([A-Za-z_][A-Za-z0-9_-.]*[A-Za-z0-9_-.$]).

This command will take account-name as argument. Rest all are optional and can be added later.


-c some-comment

This will give a short description about the user and purpose of account.

-p password

We can specify password here for the account.

-e expire

With this option the date when the account will be expired can be changed. expiredate has to be specified as number of days since January 1st, 1970. The date may also be expressed in the format YYYY-MM-DD. If not specified, the default from /etc/default/useradd is used.

-G group1,group2..

If You want the user to be member of a group or more, you can user this option. All the groups that the new user has to be member of can be given seperated by comma.

Example: 1. Add a new user "shanky"

useradd shanky [-c "A demo user"] -p mypswd


If you dont give -p some-passwd, it will ask you to give a password

2. Give a password: ******

Once this is done , you can check if the account is added or not. Use below command:


Place-holder for encrypted password




Home dir

Default shell

grep shanky /etc/passwd





A demo user




The 2nd field in this file 'x' is a place holder of the encrypted password for the user and the encrypted password is stored in /etc/shadow file.

Related Files:

/etc/passwd - user account information

/etc/shadow - shadow user account information

/etc/group - group information

/etc/default/useradd - default values for account creation

/etc/skel - directory containing default files

SEE ALSO passwd, login.defs, userdel, usermod




Category: Open System-Linux | Views: 2045 | Added by: Piyu | Tags: useradd, see an existing user, How to add a new user in Linux. Cre | Rating: 0.0/0

Related blogs

You may also like to see:

[2014-12-28][Open System-Linux]
Shift command with examples
[2014-06-05][Open System-Linux]
SCRIPT command: Save your Linux sessions automatically
[2015-04-23][Open System-Linux]
15 Great DATE command examples
[2015-07-12][Open System-Linux]
EGREP or extended grep in Linux to search patterns
[2015-06-01][Open System-Linux]
DIG command : A DNS lookup utility

Total comments: 0