Create User In Linux From Command Line And Its Options

Posted on : November 28, 2012 , Last Updated on : October 15, 2016 By
| Reply More

User administration is an important task for system administrator. She might need to add new users to the system. This article discusses how new users can be added to a system, and how the login details of a user can be customized while adding the user.

Adding User

Only root user can add any user. To add users to the system, the command used is 'useradd'. To simply add a user,

$ useradd jones

This will create the user "jones" with the default values for home directory, shell, primary group etc. The user can be customized while adding on to the system. For example, if we wish to assign a particular shell to a user, we can use -s option.

$ useradd -s /bin/sh jones

Here, /bin/sh will be the login shell for jones user.
The home directory of a user can be assigned manually with -d option.

$ useradd -d /var/jones jones

The primary group can be provided with -g option. This group must exist on the system.

$ useradd -g projectX jones

The day when user account will be disabled (i.e. the expiry date) can be provided with -e option. The date is specified in the format YYYY-MM-DD.

$ useradd -e 2013-12-31 jones

A short description for login, a comment is provided with -c option.

$ useradd -c "Jones Moore" jones

Another example of adding a user with customized login details:

$ useradd -c "Jenny Mandy" -d /var/jenny -g admin -s /bin/csh -e 2020-01-01 jenny

This will add the user 'jenny' with name "Jennny Mandy", home directory /var/jenny, default group 'admin', login shell /bin/csh, whose account expires on january 01, 2120.

All of these details can be modified after a user has been added with 'usermod' command. Most of the options used with 'usermod' are same as that of 'useradd' with the exception that 'useradd' creates a new user while 'usermod' works on an existing user. It means that while using 'useradd' command, the user must NOT exist on the system and with 'usermod' command, the user MUST exist.


Tagged With : ,

Free Linux Ebook to Download

Leave a Reply

All comments are subject to moderation.