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

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

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

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

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

You may also like...

102 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.