useradd command in Linux with Examples

useradd is a command in Linux that is used to add user accounts to your system. It is just a symbolic link to adduser command in Linux and the difference between both of them is that useradd is a native binary compiled with system whereas adduser is a Perl script which uses useradd binary in the background. It make changes to the following files:

  • /etc/passwd
  • /etc/shadow
  • /etc/group
  • /etc/gshadow
  • creates a directory for new user in /home


useradd [options] name_of_the_user

Working with useradd Command

1. To add a simple user

sudo useraddtest_user


This command will add the user named “test_user”.

2. To give a home directory path for new user

sudo useradd -d /home/test_user test_user


This will set the home directory of the us”/home/test_user”.

3. To create a user with specific user id

sudo useradd -u 1234 test_user


This will create a new user with the user-id “1234” and the name “test_user”.

4. To create a user with specific group id

sudo useradd -g 1000 test_user


This will create a new user with the group id “1000” and the name “test_user”.

5. To create a user without home directory

sudo useradd -M test_user


This will create the user with the name “test_user” and that too without a home directory.

6. To create a user with expiry date

sudo useradd -e 2020-05-30 test_user


This will create the user named “test_user” with the expiry date of 30th May 2020.

7. To create a user with a comment

sudo useradd -c "This is a test user" test_user


This will create a user with a short comment or description of the user.

8. To create a user with changed login shell

sudo useradd -s /bin/sh test_user


This will create a user named “test_user” with the default shell /bin/sh.

9 To set an unencrypted password for the user

sudo useradd -p test_password test_user


This will create a new user with the name “test_user” and an unencrypted password “test_password”.

10. To display help

sudo useradd --help


This command will display the help section of the useradd command.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.