Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

useradd command in Linux with Examples

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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

Syntax:

useradd [options] name_of_the_user

Working with useradd Command

1. To add a simple user

sudo useradd test_user

add-new-user-useradd-linux 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

create-user-with-home-directory-useradd-linux 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

create-user-with-specific-user-id 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

create-user-with-specific-group-id 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

add-user-without-home-directory 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

create-user-with-expiry-date 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

add-user-with-comment 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

add-user-with-default-shell 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

add-user-with-unencrypted-password This will create a new user with the name “test_user” and an unencrypted password “test_password”. 10. To display help

sudo useradd --help

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

My Personal Notes arrow_drop_up
Last Updated : 11 Oct, 2022
Like Article
Save Article
Similar Reads