≡ Menu

Linux add a user using command line tools

Q. How do I add a new user using command line tools? What are command line option recommended.

A. You need to use useradd command, which is responsible for creating a new user or update default new user information

The useradd command creates a new user account using the values specified on the command line and the default values from the system. The new user account will be entered into the system files (/etc/passwd) as needed, the home directory (/home/username) will be created, and initial files copied, depending on the command line options.

Task: Add a user to the system

Syntax is as follows for useradd command:
useradd <username>

By default user account is locaked, you need to setup a new password:
passwd <username>

For example add a new user called tom and set password to jerry:
# adduser tom
# passwd tom

If you want to add a user to group read how to add a user user to group

List of common options:

  • -c comment: Add a comment for the user
  • -d home-directory: Create a new home-directory
  • -e yyyy-mm-dd: Date for the account to be disabled
  • -f days: Number of days after the password expires until the account is disabled. (If 0 is specified, the account is disabled immediately after the password expires. If -1 is specified, the account is not be disabled after the password expires.)
  • -g group-name: Primary Group name or group number for the user's default group (group name must exist)
  • -G group-list: List of secondary additional (other than default) group names or group numbers, separated by commas, of which the user is a member (group name must exist)
  • -m: Create the home directory
  • -M: Do not create the home directory
  • -s: User's login shell (default /bin/bash)

To read all command line option type following command:
$ man adduser

{ 25 comments… add one }

  • maruf February 21, 2009, 5:38 pm

    thanks for your information.

  • digitalpbk May 17, 2009, 5:45 pm

    Thank you
    how do you set limits such as disk quota ?

  • bug March 3, 2010, 8:20 am

    For example add a new user called tom and set password to jerry:
    # adduser tom
    # passwd tom

    passwd in example should be:
    # passwd jerry

    • BryAnna February 5, 2011, 12:04 am

      Its actually
      useradd or adduser tom
      passwd tom
      The following prompt will come up after you input “passwd tom” than type jerry
      New UNIX password: jerry

    • john December 5, 2013, 8:26 pm

      Do you even linux?

  • newbee April 5, 2010, 3:49 pm

    Use the command called ‘quota’ to set limits for disk usage.

  • PANYE June 3, 2010, 3:03 pm

    hi please how can i change the acces pasword the ftp server ton enter in my server ebrunie-voip?
    i wont to change the access to protect my server agains some fraud.

  • An M June 26, 2010, 2:30 am

    i was looking for differences between ‘useradd’ and ‘adduser’, but you seem to mix both….

    see this:you first talk about useradd, then you put an example with adduser !

  • Annie June 24, 2011, 10:45 am

    How can i manage user from Command Line

    Let suppose i create user spiderman and grant Superuser like root!

  • Mangesh September 19, 2011, 7:54 am

    Is it possible to create user and password in single cmd?

    useradd -m user1 -p passwordforuser1

  • G8KeaPoR December 22, 2011, 4:28 pm

    Be sure to man useradd as there are a bunch of other options that this article leaves out like adding keys, names, passwords, and other things. man is your friend learn to use it or you will hate life in linux/unix

    • Falcon November 3, 2012, 8:58 pm

      I am still a bit new to UNIX but yours sounds like probably the best advice here… about man most definitely.

      On a side note… and this is just a shot in the dark. I am trying to get an Ubuntu 10.04 box, which has been upgraded and updated as of 11/2012, to run Teamspeak and a game called ArmA 2. The game has a modification called @ACRE that enhances Teamspeak. I have the Teamspeak server running and can get to it through my WAN IP. I have the mod loaded in the game server. I have the same mod loaded in the Windows client. The Teamspeak server never recognizes the the mod is loaded in the game.

      Again, I know this is a shot in the dark but maybe you know about this game or maybe you have some general suggestions.

      Anyway, thanks again for the good advice.

  • Teng Yang February 1, 2012, 7:13 pm

    What would you type at a command line to create a new user called “Susan”, but not create a password? (Susan will not be able to use her account until you set one)

  • Omi April 25, 2012, 2:39 pm

    Hello, thanks for the information, but the real question is if u want to create or give an user admin rights or root rights how do you do it…. ?

  • Uday May 29, 2012, 7:18 am

    thanks for giving the information about useradd but how do we can make user as a group

  • Ace Macleod July 19, 2012, 2:51 pm

    I know I’m late to the party but to allow a user to run root commands,
    you can do a couple things…

    A) add the user’s numeric If to the root group in /etc/group
    This is a single file but it doesn’t guarantee all root access.

    B) add them to the /etc/sudoers file.

    You need to be root to do it.
    su as root, change the permissions on /etc/sudoers to 600 then vi/nano it. After looking through the file to see the format you need to use to add the user, save the file, change the perms back to 400 (I think it was 400) otherwise sudo won’t work for the user.

    Now whenever you log in as that user, you can type in sudo and you’ll have root permissions.

    Easy as Pi
    – Ace Macleod –

  • liang November 2, 2012, 8:55 am

    hi ,
    how about add user full name

  • nithya December 17, 2012, 9:04 am

    how to create mail id for a particular user in putty server? and already i had added user name and password,after that how to proceed?

  • sameer May 10, 2013, 8:42 am

    WoW ! nice article i got it here. Thanks for sharing this information on your blog.

  • Sham kiran December 2, 2013, 4:59 am

    The command used to send the message to all users who logged or not logged in.

  • tamnq February 28, 2014, 10:57 pm

    how to su user basic to root permision

  • Andrei March 24, 2014, 11:30 pm

    Hmm… this appears simple, but for me it’s not working. I tried it like this:

    adduser -d

    But it doesn’t create anything, just lists the option. Trying to set a password confirms the username doesn’t exist. I’m a total n00b, basically just following a tutorial for installing Arch, so any ideas ?

  • name March 20, 2015, 1:15 pm

    You should explain the difference between useradd and adduser when you use both…

    useradd is the system binary, adduser is a Perl script that simplifies some things.

  • Nimish November 28, 2015, 5:52 am

    Unable to add user. The error is only root may add user or group to the system.
    can anyone explain how to resolve this.?

Leave a Comment

   Tagged with: