How to Create Users in Linux [15 useradd Command Examples]

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

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

In some Linux distributions, the ‘useradd‘ command may have a slightly different version. I suggest reading your documentation before using our instructions to create new user accounts in Linux.

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

  • It edits /etc/passwd, /etc/shadow, /etc/group, and /etc/gshadow files for the newly created user accounts.
  • Creates and populates a home directory for the new user.
  • Sets permissions and ownerships to the home directory.

Useradd Command Syntax

The basic syntax of the ‘useradd‘ command is:

useradd [options] username

In this article, we will demonstrate the 15 most commonly used ‘useradd‘ commands with practical examples in Linux.

1. How to Add a New User in Linux

To add or create a new user, you have to use the ‘useradd‘ or ‘adduser‘ command followed by the ‘username‘. The ‘username‘ is the login name a user uses to log into the system.

Only one user can be added, and the username must be unique, and not already exist on the system.

For example, to add a new user named ‘tecmint‘ use the following command:

useradd tecmint

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

passwd tecmint

Changing password for user tecmint.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
Create User in Linux
Create a User in Linux

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

tecmint:x:1000:1000:tecmint:/home/tecmint:/bin/bash
View User Info in Linux
View User Info in Linux

The above entry contains a set of seven colon-separated fields, each field having its own meaning.

Let’s see what these fields are:

  • Username – The user login name is used to log into the system. It should be between 1 and 32 characters long.
  • Password – The user password (or 'x' character) is stored in the ‘/etc/shadow‘ file in an encrypted format.
  • User ID (UID) – Every user must have a User ID (UID), which stands for User Identification Number. By default, UID 0 is reserved for the root user, and UIDs ranging from 1 to 99 are reserved for other predefined accounts. Additionally, UIDs ranging from 100 to 999 are reserved for system accounts and groups.
  • Group ID (GID) – The primary Group ID (GID), which stands for Group Identification Number, is stored in the ‘/etc/group‘ file.
  • User Info – This field is optional and allows you to define extra information about the user, such as the user’s full name. This information can be filled in using the finger command.
  • Home Directory – The absolute location of the user’s home directory.
  • Shell – The absolute location of a user’s shell i.e. /bin/bash.

2. How to Create a User with a Different Home Directory

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

However, this behavior can be changed by using the '-d' option along with the location of the new home directory (e.g., ‘/data/projects‘). For instance, the following command will create a user ‘anusha‘ with a home directory set to ‘/data/projects‘.

# useradd -d /data/projects anusha
# passwd anusha

You can view the user’s home directory and other user-related information, such as user ID, group ID, shell, and comments using the following cat command.

cat /etc/passwd | grep anusha

anusha:x:1001:1001::/data/projects:/bin/bash
Create User with Home Directory in Linux
Create a User with a Home Directory in Linux

3. How to Create a User with a Specific User ID

In Linux, every user has their own UID (Unique Identification Number). By default, when we create a new user account in Linux, it assigns user IDs 500, 501, 502, and so on.

However, we can create users with custom user IDs using the '-u' option. For example, the following command will create a user ‘navin‘ with a custom user ID ‘1002‘.

useradd -u 1002 navin

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

cat /etc/passwd | grep navin

navin:x:1002:1002::/home/navin:/bin/bash
Create User with User ID in Linux
Create a User with the User ID in Linux

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

4. How to Create a User with a Specific Group ID

Similarly, every user has their own GID (Group Identifier). We can create users with specific group IDs as well using the '-g' option.

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

useradd -u 1005 -g tecmint tarunika

Now, check the assigned user ID and group ID in the ‘/etc/passwd‘ file.

cat /etc/passwd | grep tarunika

tarunika:x:1005:1000::/home/tarunika:/bin/bash

To verify the user’s GID, use the id command:

id -gn tarunika
Create User with Group ID in Linux
Create a User with Group ID in Linux

5. How to 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.

In this example, we are adding a user ‘tecmint‘ to multiple groups, such as admins, webadmin, and developers.

groupadd admins
groupadd webadmin
groupadd developers
usermod -a -G admins,webadmin,developers tecmint
useradd -G admins,webadmin,developers paddy

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

id tecmint

uid=1000(tecmint) gid=1000(tecmint)
groups=1000(tecmint),1007(admins),1008(webadmin),1009(developers)
context=root:system_r:unconfined_t:SystemLow-SystemHigh
Add User to Group in Linux
Add User to Group in Linux

6. How to Add a User Without Home Directory

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

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

useradd -M shilpi

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

ls -l /home/shilpi

ls: cannot access /home/shilpi: No such file or directory
Create User Without Home Directory in Linux
Create User Without Home Directory in Linux

7. How to Create a User With an Expiry Date in Linux

By default, when we add users with the ‘useradd‘ command, the user account never expires, meaning their expiry date is set to 0 (which means never expired).

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

In this example, we create a user ‘aparna‘ with an account expiry date, which is 27th August 2021, in the YYYY-MM-DD format.

useradd -e 2021-08-27 aparna

Next, verify the account and password aging information using the ‘chage‘ command for the user ‘aparna‘ after setting the account expiry date.

chage -l aparna

Last password change					: Jun 25, 2021
Password expires					: never
Password inactive					: never
Account expires						: Aug 27, 2021
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
Create User With Account Expiry Date
Create User With Account Expiry Date

8. How to 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 inactivates the user account as soon as the password has expired. By default, the password expiry value is set to -1, which means it never expires.

In this example, we will set an account password expiry date, which is 45 days, for a user ‘mansi‘ using the '-e' and '-f' options.

useradd -e 2014-04-27 -f 45 mansi
Create User With Password Expiry Date
Create User With Password Expiry Date

9. How to Add a User with Comments in Linux

The '-c' option allows you to add custom comments, such as the user’s full name, phone number, etc., to the ‘/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 insert that user’s full name, Manis Khurana, into the comment field.

useradd -c "Manis Khurana" mansi

You can view the inserted comment in the ‘/etc/passwd‘ file in the comments section using the tail command.

tail -1 /etc/passwd

mansi:x:1010:1013:Manis Khurana:/home/mansi:/bin/sh
Create User with Full Name
Create User with Full Name

10. How to Create a User Login Shell in Linux

Sometimes, we add users who have nothing to do with the login shell or sometimes we are required to assign different shells to our users. We can assign different login shells to each user with the ‘-s‘ option.

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

useradd -s /sbin/nologin tecmint

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

tail -1 /etc/passwd

tecmint:x:1011:1014::/home/tecmint:/sbin/nologin
Create User with Login Shell
Create a User with a Login Shell

11. How to Create a User with Specified Home, Shell, and Comment

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

useradd -m -d /var/www/ravi -s /bin/bash -c "TecMint Owner" -U ravi
Create User with Home Directory and Login Shell
Create a User with Home Directory and Login Shell

In the above command, the options '-m' and '-d' creates a user with a specified home directory, and the '-s' option sets the user’s default shell to /bin/bash. The '-c' option adds extra information about the user and the '-U' argument creates/adds a group with the same name as the user.

12. How to Create a User with a Defined Home, Shell, Comment, UID/GID

The command is very similar to the one above, but here we define the shell as ‘/bin/zsh‘ and set custom UID and GID for a user ‘tarunika‘. The '-u' option defines the new user’s UID (i.e., 100), and the '-g' option defines the GID (i.e., 1000).

useradd -m -d /var/www/tarunika -s /bin/zsh -c "TecMint Technical Writer" -u 1000 -g 100 tarunika
Create User with UID and GID
Create a User with UID and GID

13. How to Create a User with Home, No Shell, Comment, and UID

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

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

useradd -m -d /var/www/avishek -s /usr/sbin/nologin -c "TecMint Sr. Technical Writer" -u 1019 avishek
Create User with UID and Nologin
Create a User with UID and Nologin

14. How to Create a User with a Specified Home, Shell, Skeleton, and UID

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

useradd -m -d /var/www/navin -k /etc/custom.skell -s /bin/tcsh -c "No Active Member of TecMint" -u 1027 navin
Create User with Shell and UID
Create a User with Shell and UID

15. How to Create a User without Home, Shell, or Group, with Comment

The following command is very different from the other commands explained above. Here, we used the '-M' option to create a user without the user’s home directory, and the '-N' option is used to instruct the system to only create a username (without a group). The '-r' option is for creating a system user.

useradd -M -N -r -s /bin/false -c "Disabled TecMint Member" clayton
Create User with NoLogin and Group
Create a User with NoLogin and Group

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

useradd

If you want to modify user account attributes such as modifying the username, user ID (UID), home directory, shell, and more, use the usermod command.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

119 Comments

Leave a Reply
  1. Section 3. Create a User with Specific User ID – >

    With reference to this statement – “By default, whenever we create a new user accounts in Linux, it assigns userid 500, 501, 502 and so on…”

    Doesn’t Linux create a new user and assign UID to new users by default from – 1001, 1002, 1003 … onwards, instead of 500 ?

    Reply
    • “Doesn’t Linux create a new user and assign UID to new users by default from – 1001, 1002, 1003 … onwards, instead of 500 ?”

      Depends on the distro. Some start at 500. It is also possible to change the starting number to almost anything you please, as long as the user numbers do not conflict with preset root/system numbers.

      Reply
    • @Yogesh,

      I hope this following command will help you to add user and password with one single command.

      $ sudo useradd username; echo password | passwd username --stdin
      
      Reply
  2. I cannot get the ‘adduser‘ or ‘useradd‘ commands to work. Whenever I try I get the prompt “bash: useradd: command not found”

    Reply
  3. Thanks again for your response.

    Quick question- If the user joins signs in/out the following day, it will be the closet possible date of creation – correct?

    e.g. I created user john on Jan 30 and the sign joins organization on Jan 31 and signs in/out, this is when .bash_logout will be created -correct?

    Thanks

    Reply
  4. I created a new user and it came up with some results, not so relevant to the user creation date. However, it seems like showing me authentication success or failure for the user.

    Any further ideas?

    Reply
    • @Harry,

      To find out correct user creation date in Linux, you need to check the stats of .bash_logout file in your home directory.

      $ stat /home/tecmint/.bash_logout
      
      Sample Output
        File: /home/tecmint/.bash_logout
        Size: 220       	Blocks: 8          IO Block: 4096   regular file
      Device: 803h/2051d	Inode: 6162417     Links: 1
      Access: (0644/-rw-r--r--)  Uid: ( 1000/ tecmint)   Gid: ( 1000/ tecmint)
      Access: 2020-01-02 12:16:13.475201521 +0530
      Modify: 2019-02-15 17:23:35.675059936 +0530
      Change: 2019-02-15 17:23:35.675059936 +0530
       Birth: -
      

      In the output above highlighted, shows the correct user creation date..

      Reply
  5. I installed and run without any luck. It returned no results. I double-checked /etc/passwd to confirm if the user I am testing with existed.

    I checked the status and restarted the service auditd.

    # systemctl status auditd
    # systemctl restart auditd 
    

    Is there anything I am missing?

    Thanks

    Reply
  6. Hey,

    How can I create a user which shows the date of creation (date stamp) so that IS security can audit it, down the road. It would be great if it is for RHEL or Ubuntu distros.

    Thanks

    Reply
    • @Harry,

      To Find Out When a User is Created in Linux, you can check the stat of .bash_logout file, as this file is created upon the user’s first logout.

      # stat /home/username/.bash_logout 
      
      Reply
      • Thank you for your quick response.

        At work, I have a scenario where we generally create a user a day in advance of his joining date. If I follow, what you said I can get approximation and not exact date as a user will log in and logout the following day. However, our IS security team wants to know the time stamp of user creation or their audit. Do you recommend any other way to know the creation date?

        Reply
        • @Harry,

          If you have auditd installed on the system, you can find out the user creation date and time.

          # aureport --auth | grep username
          

          Alternatively, you can find the user creation in /var/log/secure file..

          Reply
  7. I am not able to set a password for a new user, it shows heading New password but it does not type anything neither any alphabetical letter nor a number.

    Please help me.

    Reply
  8. Example 5)

    if the user is already exit command should be:

    # usermod -G admins,webadmin,developers tecmint
    

    If you are adding the new user to additional groups then command:

    # useradd -G 
    

    is correct…

    Reply
  9. 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‘.

    [root@tecmint ~]# useradd -u 999 navin
    

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

    [root@tecmint ~]# cat /etc/passwd | grep tecmint
    
    navin:x:999:999::/home/tecmint:/bin/bash
    

    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?

    Reply
    • -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.

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

    "tecmint:x:504:504:tecmint:/home/tecmint:/bin/bash"
    

    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.

    Reply
  11. 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.

    Reply
  12. 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.

    Reply
    • @Senor,

      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
      
      Reply
  13. When I am creating user with another director I am getting this error:

    useradd: can not create directory /data/projects
    
    Reply
    • @Madhav,

      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
      
      Reply
  14. 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.

    Reply
    • @Revathi,

      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?

      Reply
  15. 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.

    Reply
  16. 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'
    
    Reply
  17. Hi Ravi, I have a question, If use: su “user” type the password and the system say: su: System Error, why is this message?

    Reply
  18. Hi Sir,

    I have a one question..

    How to create a user with custom primary group and then add this user to secondary group in one command, this question asked in interview .

    ex: username – techmint
    primary group name – linux
    secondary group name – admin

    Reply
    • @Pramod,

      Use following command add a new user to primary group (-g option) and secondary group (-G option).

      # useradd -g linux -G admin techmint
      
      Reply
  19. Hi, I am new for learning Linux from basic to advanced level I think your blog is best to everyone to learn thanks for providing such a great tutorial and articles.

    Reply
  20. The result does not match search criteria right?

    [root@tecmint ~]# cat /etc/passwd | grep tecmint
    navin:x:999:999::/home/navin:/bin/bash

    Reply
    • @Andrea,

      Yes, search criteria for user ‘tecmint’ was wrong, but thanks for pointing out, we’ve corrected in the writeup..

      Reply
  21. I am adding a user “sudo useradd test” in RHEL. I am getting “configuration error – unknown item ‘TMOUT=600;’ (notify administrator)”. But user is getting created. However when I try to login I am unable to login ad test. Any idea why so?

    Reply
  22. I tried using ‘useradd,’ and no home folder was created, also, when trying to switch from ‘root’ to the new user created, I got the message “No directory, logging in with HOME=/.”

    It worked fine until I used ‘adduser’ instead of ‘useradd’. This way the /home/user1 folder was created, and I was able to switch from ‘root’ to ‘user1’ using ‘su – user1’ command.

    After all, ‘useradd’ and ‘adduser’ are not as similar as one would think.

    Reply
    • Excellent suggestion. I had the exact same issue. This article needs to be modified to reflect this issue. The commands are not the same and they perform different functions.

      Reply
  23. Is it possible to have an account that has no shell, not a root account and it has sftp access by using winscp? I’m setting up a linux box with Litespeed so I would like to have a locked down account that only used for uploading and running the server service.

    Reply
  24. how to create multiple users with same home directory .

    like we have 5 user test1, test2,test3,test4,test5 and share with same home directory like /home/job .

    condition :- user should have not have own directory they will access only /home/job.

    please guide how can we create ???

    Reply
    • @Anshoo,

      First create a shared directory, for example /home/shared and give appropriate permissions to this folder so that all users can able to edit or write to this directory. Next add new users to this directory with the help of following command.

      # useradd -d /home/shared/ -u user1
      
      Reply
    • @Gabe,

      There are many reasons to disable shell access to a user, for example FTP uploads, samba share users, nfs share users, etc.

      Reply
  25. On my system (Ubuntu 14.04) I need to specify the command line switch “-m” in order to get the useradd command to automatically create the required home directory. Otherwise the useradd command creates the user, with the required home directory listed in their user properties, but doesn’t actually create the physical directory entry. Same with use of “-d” switch for a non-standard home directory.
    Thought you might like to add this to your tutorial. Ta.

    Reply
  26. useradd -d /data/projetcs anusha ……………….. when i am trying to add a user with different home directory…this command is working for me…
    its show an error “cannot create directory /data/projects” .. please help me out asap ..

    Reply
  27. Is it possible to specify/limit the size of particular user’s home directory.
    for example : create a user “abc”, then /home/abc should be allowed to store only 5GB(not more than that).

    Reply
      • Hi Ravi,
        I had similar query as Angie, I tried to add 4 users one by one in a group.
        however, when tried to see output of below it still show user added at first.

        cat /etc/group | grep xyz
        out I am expecting is
        xyz:: 111: user1, user2,user3,user4

        however, result I am getting as below
        xyz:111: user1

        kindly suggest

        Reply
    • 1 – create a file where all users are in there. Something like a list
      2 – cat it, then use xargs. Something like

      ~]# cat user.lst | xargs -i useradd {}

      With the same concept you can set password as well.

      Cheers

      Reply
  28. Is there a useradd -e command that makes the user change their password after they have logged in for the first time?

    Reply
    • Hi Bill,

      You can also try this. First change user’s password then run chage -d 0 username. Here -d will set days left for password expire to 0. So as soon as user enter his or her password it will prompt to change the password.

      Reply
  29. Hello,

    I created a new user and I want to set for it just some commands to run ( eg. create to db, add a column, etc.) . How I do that? Thanks a lot!

    Reply
  30. how can i find particular user full name in linux?? i mean which username assigned to which user in the company .?

    Reply
  31. Without using usermod, how can you add a user, leaving the default group, but also add an additional group:
    useradd -m -g username -G additonalgroup username
    …this doesn’t work, and complains that username group doesn’t exit yet

    useradd -m -G additionalgroup username
    …this doesn’t work, as it doesn’t add them to their default username group

    Can’t seem to find the proper syntax.

    Reply
  32. Hello Sir,
    When we simply add any user by useradd it automatically create directory under /home, or we also can define it by giving path to particular folder for that users home directory.
    But when i add new user i want to change users home directory permanently to other location by default .

    so is there any configuration file where it is define about users default path for create home directory.

    example i’ve added user “test” then it create directory by default under “/home/test” coz somewhere it is defined that.

    but i want that configuration file so i can change default path for home directory.

    also when i add domain user in Active Directory it also goes under /home/
    i also want to change that home directory location.

    so please if u have any idea plz reply asap. Thnx .. :))

    Reply
    • @Mori,
      Just use the -d (defines home directory for user) option along with useradd command to create a new user with specified directory path. I’ve already showed about that -d option in the article, just read carefully…all options of useradd command in the article.

      Reply
    • @Ruchi,
      Thanks for such kind words….we will continue to write and such great articles for our readers like you..keep connected…:)

      Reply
    • @Rufus,
      For newbies, I suggest Fedora, Ubuntu, Zorin OS or Linux Mint, for experts CentOS, RHEL, Debian, Arch or Gentoo..Now its upto you what to choose..

      Reply
  33. How do I create a user which can work on his home directory only? The user is should be restricted to change directory or access other files accept his home directory.

    Reply
  34. “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‘.”

    “However, this behavior can be overriden by using the -d option followed by the full path for the desired new home directory (which need not be in /home). For example, the following would create a new user named jim with a home directory /home/james:”

    Come on, this post is just a copy of http://www.linfo.org/useradd.html (a copyrighted source), paraphrased just enough that it’s difficult to google the similarities. If this is a paid piece, I believe there’s some attribution missing, and that’s being /very/ kind.

    Reply
  35. Awesome Article dear…

    Captured all possible options. You just saved my time in search of other articles on this.

    Reply
  36. Hi,

    I want to create a 3 different type of user with below privilege in Sun Solaris and Linux platform.

    1) read only
    2) read and write only
    3) admin

    Can you help on this. How I do the same.

    Reply
    • @Naveen,
      You can’t create users in your own way..in Linux every user created with default permissions, you need to play with these permissions to achieve your goals.

      Reply
  37. very nicely described…Ravi

    ple let me know the command for set all user(who store in one group ) password at one time .

    Reply
  38. The beginning of the guide is wrong. I’ve never used a linux system where useradd and adduser were the same. They are different programs!
    In fact that is always something annoying I have to check, since I cant remember which one I want when I finally want to add a user. (maybe 1-2 times a year)

    Reply
  39. Systems and
    networks
    Q1:
    Create a shell script named
    scriptadduser.sh
    which will take
    a name or names of
    users on command line along with script itself, and add a user and a home directory for
    the use
    how to solve this quation pls fast

    Reply
  40. Dear ,

    Could you please explain me why it is needed to create a system account and why the need to change the login shell to usr/sbin/nologin.

    Please reply.

    Reply
  41. very nicely described .. i am a Java developer .. need to work with some RPM stuff and know about Linux user management . This article helped me to understand the concept very clearly. Thanks a ton ..friend .. keep doing the good work ..cheers .

    Reply
  42. WARNING: useradd -G [group1,group2,group3…] will replace ALL existing groups the user is a member of, with the groups specified

    What you probably want to use is:
    useradd -a -G [group1, group2, group3…]

    -a or –append does exactly that. Without it, the default behaviour is to replace all group membership.

    It’s amazing that so few sites documenting how to add users to a group mention this fact… I just had to boot in to recovery mode to fix my login, as I accidentally removed my account from the ‘sudo’ group (along with all other groups). I hope this saves just one user from yelling at their computer ;)

    Reply
  43. The article is very clear and precise and good article to freshers and hope in comming days more posts to see from you ..:)

    Reply
    • Siva, thanks for such words, yes we are in process of providing such useful articles to our fellow readers like you. Stay tuned for such more awesome articles.

      Reply
  44. Hi Ravi,

    Really very useful introduction with nice helpful examples.
    Hope to see more from you soon.
    Thank you for sharing your knowledge with us and giving us chance to learn from your experience.
    Best regards

    Reply
  45. Hi,

    Kindly explain me if we create a user by useradd ,, will it create a group automatically in the name of the user itself ??

    example :
    #useradd -d /ebiz/raja raja — now there will be a directory created under /ebiz mount point as raja

    #passed raja – creates password thats it,,

    now explain me the above mentioned user has its own GROUP as the username ???

    I wanted to create a group and wanted to add some users into that with their own folder ,, how to do that,,

    Some one explain me

    Reply
    • Yes, when creating a user with useradd command the group also created with the same username. You can use -G or -g option to add uses to groups.

      Reply
  46. HI Ravi,

    Your article is very good. I have a question on user’s

    Q) How to check when the user was created? ( Date and time)

    Thanks in advance.

    Reply
  47. Awesome article thank you very much for this post.

    I really liked your articles and it’s easy to understand . Please post many :)

    Reply
  48. Seems to me that articles like this are what scare people away from Linux. I know commands are useful, and use many myself. Yet I have yet to use a Linux OS that would not let me add a user through the GUI. Maybe that should be explained first, then on to commands. I know the terminal and command line kept me from using Linux for years. Once I found out how easy things now are, exclusive Linux user for 2 years.

    Reply
  49. Nice article but one nit. The password is not stored in encrypted form in the /etc/shadow file. That implies the password could be recovered if one knew the key. Instead, a hash is made of the password and it is the hash that is stored. It is all but impossible to recover the password from the hash value and highly improbable that one could find an alternate password that would have the same hash.

    Reply
    • Even if one did not have access, let alone root access, getting any password, even root is simple. An easy exploitation, whether it be physical starting with nmap, or social, starting with looking for users on the website if the company has one can have one running…

      # cat /etc/shadow

      … in no time. From there it is a simple matter of copying the hashed line for the specific user, realizing that root starts at 0, and running john the ripper or hydra on it. Most high school kids could do this these days I would guess.

      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.