The Complete Guide to “useradd” Command in Linux – 15 Practical Examples

We all are aware about the most popular command called ‘useradd‘ or ‘adduser‘ in Linux. There are times when a Linux System Administrator asked to create user accounts on Linux  with some specific properties, limitations or comments.

In Linux, a ‘useradd‘ command is a low-level utility that is used for adding/creating user accounts in Linux and other Unix-like operating systems. The ‘adduser‘ is much similar to useradd command, because it is just a symbolic link to it.

add users in linux

useradd command examples

In some other Linux distributions, useradd command may comes with lightly difference version. I suggest you to read your documentation, before using our instructions to create new user accounts in Linux.

When we run ‘useradd‘ command in Linux terminal, it performs following major things:

  1. It edits /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow files for the newly created User account.
  2. Creates and populate a home directory for the new user.
  3. Sets permissions and ownerships to home directory.

Basic syntax of command is:

useradd [options] username

In this article we will show you the most used 15 useradd commands with their practical examples in Linux. We have divided the section into two parts from Basic to Advance usage of command.

  1. Part I: Basic usage with 10 examples
  2. Part II: Advance usage with 5 examples
Part I – 10 Basic Usage of useradd Commands

1. How to Add a New User in Linux

To add/create a new user, all you’ve to follow the command ‘useradd‘ or ‘adduser‘ with ‘username’. The ‘username’ is a user login name, that is used by user to login into the system.

Only one user can be added and that username must be unique (different from other username already exists on the system).

For example, to add a new user called ‘tecmint‘, use the following command.

[[email protected] ~]# useradd tecmint

When we add a new user in Linux with ‘useradd‘ command it gets created in locked state and to unlock that user account, we need to set a password for that account with ‘passwd‘ command.

[[email protected] ~]# passwd tecmint
Changing password for user tecmint.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

Once a new user created, it’s entry automatically added to the ‘/etc/passwd‘ file. The file is used to store users information and the entry should be.


The above entry contains a set of seven colon-separated fields, each field has it’s own meaning. Let’s see what are these fields:

  1. Username: User login name used to login into system. It should be between 1 to 32 charcters long.
  2. Password: User password (or x character) stored in /etc/shadow file in encrypted format.
  3. User ID (UID): Every user must have a User ID (UID) User Identification Number. By default UID 0 is reserved for root user and UID’s ranging from 1-99 are reserved for other predefined accounts. Further UID’s ranging from 100-999 are reserved for system accounts and groups.
  4. Group ID (GID): The primary Group ID (GID) Group Identification Number stored in /etc/group file.
  5. User Info: This field is optional and allow you to define extra information about the user. For example, user full name. This field is filled by ‘finger’ command.
  6. Home Directory: The absolute location of user’s home directory.
  7. Shell: The absolute location of a user’s shell i.e. /bin/bash.

2. Create a User with Different Home Directory

By default ‘useradd‘ command creates a user’s home directory under /home directory with username. Thus, for example, we’ve seen above the default home directory for the user ‘tecmint‘ is ‘/home/tecmint‘.

However, this action can be changed by using ‘-d‘ option along with the location of new home directory (i.e. /data/projects). For example, the following command will create a user ‘anusha‘ with a home directory ‘/data/projects‘.

[[email protected] ~]# useradd -d /data/projects anusha

You can see the user home directory and other user related information like user id, group id, shell and comments.

[[email protected] ~]# cat /etc/passwd | grep anusha


3. Create a User with Specific User ID

In Linux, every user has its own UID (Unique Identification Number). By default, whenever we create a new user accounts in Linux, it assigns userid 500, 501, 502 and so on…

But, we can create user’s with custom userid with ‘-u‘ option. For example, the following command will create a user ‘navin‘ with custom userid ‘999‘.

[[email protected] ~]# useradd -u 999 navin

Now, let’s verify that the user created with a defined userid (999) using following command.

[[email protected] ~]# cat /etc/passwd | grep navin


NOTE: Make sure the value of a user ID must be unique from any other already created users on the system.

4. Create a User with Specific Group ID

Similarly, every user has its own GID (Group Identification Number). We can create users with specific group ID’s as well with -g option.

Here in this example, we will add a user ‘tarunika‘ with a specific UID and GID simultaneously with the help of ‘-u‘ and ‘-g‘ options.

[[email protected] ~]# useradd -u 1000 -g 500 tarunika

Now, see the assigned user id and group id in ‘/etc/passwd‘ file.

[[email protected] ~]# cat /etc/passwd | grep tarunika


5. Add a User to Multiple Groups

The ‘-G‘ option is used to add a user to additional groups. Each group name is separated by a comma, with no intervening spaces.

Here in this example, we are adding a user ‘tecmint‘ into multiple groups like admins, webadmin and developer.

[[email protected] ~]# useradd -G admins,webadmin,developers tecmint

Next, verify that the multiple groups assigned to the user with id command.

[[email protected] ~]# id tecmint

uid=1001(tecmint) gid=1001(tecmint)

6. Add a User without Home Directory

In some situations, where we don’t want to assign a home directories for a user’s, due to some security reasons. In such situation, when a user logs into a system that has just restarted, its home directory will be root. When such user uses su command, its login directory will be the previous user home directory.

To create user’s without their home directories, ‘-M‘ is used. For example, the following command will create a user ‘shilpi‘ without a home directory.

[[email protected] ~]# useradd -M shilpi

Now, let’s verify that the user is created without home directory, using ls command.

[[email protected] ~]# ls -l /home/shilpi

ls: cannot access /home/shilpi: No such file or directory

7. Create a User with Account Expiry Date

By default, when we add user’s with ‘useradd‘ command user account never get expires i.e their expiry date is set to 0 (means never expired).

However, we can set the expiry date using ‘-e‘ option, that sets date in YYYY-MM-DD format. This is helpful for creating temporary accounts for a specific period of time.

Here in this example, we create a user ‘aparna‘ with account expiry date i.e. 27th April 2014 in YYYY-MM-DD format.

[[email protected] ~]# useradd -e 2014-03-27 aparna

Next, verify the age of account and password with ‘chage‘ command for user ‘aparna‘ after setting account expiry date.

[[email protected] ~]# chage -l aparna

Last password change						: Mar 28, 2014
Password expires						: never
Password inactive						: never
Account expires							: Mar 27, 2014
Minimum number of days between password change		        : 0
Maximum number of days between password change		        : 99999
Number of days of warning before password expires		: 7

8. Create a User with Password Expiry Date

The ‘-f‘ argument is used to define the number of days after a password expires. A value of 0 inactive the user account as soon as the password has expired. By default, the password expiry value set to -1 means never expire.

Here in this example, we will set a account password expiry date i.e. 45 days on a user ‘tecmint’ using ‘-e‘ and ‘-f‘ options.

[[email protected] ~]# useradd -e 2014-04-27 -f 45 tecmint

9. Add a User with Custom Comments

The ‘-c‘ option allows you to add custom comments, such as user’s full name, phone number, etc to /etc/passwd file. The comment can be added as a single line without any spaces.

For example, the following command will add a user ‘mansi‘ and would insert that user’s full name, Manis Khurana, into the comment field.

[[email protected] ~]# useradd -c "Manis Khurana" mansi

You can see your comments in ‘/etc/passwd‘ file in comments section.

[[email protected] ~]# tail -1 /etc/passwd

mansi:x:1006:1008:Manis Khurana:/home/mansi:/bin/sh

10. Change User Login Shell:

Sometimes, we add users which has nothing to do with login shell or sometimes we require to assign different shells to our users. We can assign different login shells to a each user with ‘-s‘ option.

Here in this example, will add a user ‘tecmint‘ without login shell i.e. ‘/sbin/nologin‘ shell.

[[email protected] ~]# useradd -s /sbin/nologin tecmint

You can check assigned shell to the user in ‘/etc/passwd‘ file.

[[email protected] ~]# tail -1 /etc/passwd

Part II – 5 Advance Usage of useradd Commands

11. Add a User with Specific Home Directory, Default Shell and Custom Comment

The following command will create a user ‘ravi‘ with home directory ‘/var/www/tecmint‘, default shell /bin/bash and adds extra information about user.

[[email protected] ~]# useradd -m -d /var/www/ravi -s /bin/bash -c "TecMint Owner" -U ravi

In the above command ‘-m -d‘ option creates a user with specified home directory and the ‘-s‘ option set the user’s default shell i.e. /bin/bash. The ‘-c‘ option adds the extra information about user and ‘-U‘ argument create/adds a group with the same name as the user.

12. Add a User with Home Directory, Custom Shell, Custom Comment and UID/GID

The command is very similar to above, but here we defining shell as ‘/bin/zsh‘ and custom UID and GID to a user ‘tarunika‘. Where ‘-u‘ defines new user’s UID (i.e. 1000) and whereas ‘-g‘ defines GID (i.e. 1000).

[[email protected] ~]# useradd -m -d /var/www/tarunika -s /bin/zsh -c "TecMint Technical Writer" -u 1000 -g 1000 tarunika

13. Add a User with Home Directory, No Shell, Custom Comment and User ID

The following command is very much similar to above two commands, the only difference is here, that we disabling login shell to a user called ‘avishek‘ with custom User ID (i.e. 1019).

Here ‘-s‘ option adds the default shell /bin/bash, but in this case we set login to ‘/usr/sbin/nologin‘. That means user ‘avishek‘ will not able to login into the system.

[[email protected] ~]# useradd -m -d /var/www/avishek -s /usr/sbin/nologin -c "TecMint Sr. Technical Writer" -u 1019 avishek

14. Add a User with Home Directory, Shell, Custom Skell/Comment and User ID

The only change in this command is, we used ‘-k‘ option to set custom skeleton directory i.e. /etc/custom.skell, not the default one /etc/skel. We also used ‘-s‘ option to define different shell i.e. /bin/tcsh to user ‘navin‘.

[[email protected] ~]# useradd -m -d /var/www/navin -k /etc/custom.skell -s /bin/tcsh -c "No Active Member of TecMint" -u 1027 navin

15. Add a User without Home Directory, No Shell, No Group and Custom Comment

This following command is very different than the other commands explained above. Here we used ‘-M‘ option to create user without user’s home directory and ‘-N‘ argument is used that tells the system to only create username (without group). The ‘-r‘ arguments is for creating a system user.

[[email protected] ~]# useradd -M -N -r -s /bin/false -c "Disabled TecMint Member" clayton

For more information and options about useradd, run ‘useradd‘ command on the terminal to see available options.

Read Also: 15 usermod Command Examples

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide
The Complete Linux System Administrator Bundle
Become an Ethical Hacker Bonus Bundle

You may also like...

114 Responses

  1. Madhav says:

    Example no 3)

    But, we can create user’s with custom userid with ‘-u‘ option. For example, the following command will create a user ‘navin‘ with custom userid ‘999‘.

    [[email protected] ~]# useradd -u 999 navin

    Now, let’s verify that the user created with a defined userid (999) using following command.

    [[email protected] ~]# cat /etc/passwd | grep tecmint

    You created user navin with uid 999. in verification command you are checking for tecmint user and output user login name is correct that is navin and home dir is /home/tecmint … how?

  2. Aditya Garg says:
    • -f switch is incorrectly explained above.
    • -e for expiry date of account.
    • -f, --inactive INACTIVE: The number of days after a password expires until the account is permanently disabled. A value of 0 disables the account as soon as the password has expired, and a value of -1 disables the feature.

    If not specified, useradd will use the default inactivity period specified by the INACTIVE variable in /etc/default/useradd, or -1 by default.

    NOTE-chage uses: -E and -M (max days) for password expiry days after setting a new password.

  3. dragonmouth says:

    In Example #1 you did not specify either the UID or the GID but:


    Please explain why, if UIDs 100-999 are reserved for system accounts and groups, why does ‘tecmint’ have UID of 504 and a GID of 504? Is ‘tecmint’ a system account? Based on the commands you used to set up user ‘tecmint’ the default UID and GID should be 1000. You did not specify

    I know that in Linux one can permanently change the default starting UID and GID number. But in this case you have not done so.

  4. Santhosh Kumar says:

    Hi, I want to create a user who will have permission to read only files in his home directory. This user should not be able to read files in the etc and dev kind of folders. So how can I create this user.

    Tried setfacl but there is no support for it in my board.

  5. Senor Catypus says:

    Unfortunately, this article had me extremely pissed off at Debian 9.

    # adduser USER
    # usermod -aG sudo USER

    is all that’s required to set up a user + home directory in Debian 9 and CentOS I believe.

    This article had me wondering why the “superior” useradd was not creating my home directory.

    • Ravi Saive says:


      To create a Sudo User on Debian, first you need log in to your system as the root user and run the following command to create a sudo user.

      # adduser username

      Next, add the user to the sudo group.

      # usermod -aG sudo username

      Verify the sudo access.

      # su - username
      $ sudo whoami
  6. madhav khating says:

    When I am creating user with another director I am getting this error:

    useradd: can not create directory /data/projects
    • Ravi Saive says:


      The easiest solution here, is to create the parent directory structure before calling useradd:

      # mkdir -p /data/projects
      # useradd --create-home --home-dir /data/projects --shell /bin/bash username
  7. Revathi says:

    Hii Sir,

    After creating an user and setting a password to it, there are so many created users are visible on the terminal. So,how can I get only the one user which I hav been created on the terminal.

    • Ravi Saive says:


      While creating user, you must have specified username on the terminal, for example.

      # useradd revathi
      # passwd revathi

      So don’t you remember the user you created?

  8. Decontee K Sawyer says:

    Hi Ravi. Your suggestion to go directly to the source documentation to understand the requirements and details is an exceedingly excellent one. You have obviously done so, and translated the English it is written in, into whatever your native language is. A link to your interpretation, in your native language would be more helpful than the confusing broken English found here.

  9. Anuj says:

    Hi Ravi,

    I have one problem, from client side I have a request to add a new user with username having space, I mean username of two words.

    For example,

    # adduser "ravi gen"
    adduser: invalid user name 'ravi gen'
  10. oscar javier guerrero says:

    Hi Ravi, I have a question, If use: su “user” type the password and the system say: su: System Error, why is this message?

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.