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.

FORMAT:

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.


Options:

-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:

user-name

Place-holder for encrypted password

uId

gId

Comment

Home dir

Default shell

grep shanky /etc/passwd

shanky

x

1234

2345

A demo user

/home/shanky

/bin/bash

 

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: 1818 | 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-10-06][Open System-Linux]
Time command in Linux to give resource usage
[2014-02-27][Open System-Linux]
RSYNC : A command in linux to copy files remotely. Faster and more flexible than rcp
[2014-09-26][Open System-Linux]
Traceroute command in Linux
[2014-10-25][Open System-Linux]
XMLWF command in Linux to check/validate/parse an XML file
[2014-09-20][Open System-Linux]
Export command in Linux

Total comments: 0
avatar