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


[2016-12-25][Open System-Linux]
Guide for working with zipped and archived files in Linux/AIX
[2016-02-05][Open System-Linux]
Lets try to understand sticky bit concept in Linux!
[2014-12-24][Open System-Linux]
XARGS command in Linux with examples
[2014-02-12][Open System-Linux]
SCP a secure copy program in Linux
[2014-12-22][Open System-Linux]
Key mapping inside VI editor

Total comments: 0
ComForm">
avatar