6:35 PMCreate 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.
This will give a short description about the user and purpose of account.
We can specify password here for the account.
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.
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"
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:
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.
/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
You may also like to see:
|Shift command with examples|
|SCRIPT command: Save your Linux sessions automatically|
|15 Great DATE command examples|
|EGREP or extended grep in Linux to search patterns|
|DIG command : A DNS lookup utility|
|Total comments: 0|