≡ Menu

How to create a new Linux user account?

The question is – How to create a new user account? How to set the password of the newly created user account? How do I disable a user account? Are there shell commands that can be used on a Linux terminal?

The command to create a new user on a Linux / Unix system is adduser. The adduser command can be used to create a new user and assign a home directory to the user.

adduser -d /home/ewhathow ewhathow

The above command will create a new user ewhathow and assign the home directory /home/ewhathow to it.

To create a password for the newly added user:

passwd ewhathow

This will allow you to create a password for the user.

adduser (or useradd) uses a set of defaults that are used when creating a new user.

Type in the following command to see the defaults:

adduser -D

This will display something like the following:

GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

To change any of these options, use the adduser command with the -D argument.

For example:

adduser -D -b /home/

The above command will change the default base directory when a user is created. The username of the new user will be appended to the base directory. So if you create a user called ewhathow, the home directory will be /home/ewhathow. This way, you don’t have to use the -d option.

Some other options that adduser users are:

-d The user's home directory
-b The base directory after which the user's name will be appended
-e expire date after which the user's account will be disabled
-f the number of days after the password expires until the account is disabled
-g group assigned to the user when created

To delete a user from the system, use the following command

userdel ewhathow

If you use the -r argument to userdel, it will remove all files and directories in the user’s home directory.

userdel -r ewhathow

Be sure to create a backup of the files in the user’s home directory before using the -r option!

To disable or lock an existing user, use the following command:

passwd -l ewhathow

This will lock the user ewhathow. To enable the account again, use the following command:

passwd -u ewhathow

{ 0 comments… add one }

Leave a Comment