Linux add a user using command line tools

Posted on in Categories last updated September 25, 2006

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

29 comment

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

    passwd in example should be:
    # passwd jerry

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

    2. Actually the example is right because as soon as you type the username after the password the command line prompts you to enter the new password and then prompts you to do the same. And anyways how is it supposed to know which username’s password to change?

  2. 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.
    thank
    panye

  3. 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 !

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

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

  5. 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)

  6. 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…. ?

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

  8. 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?

  9. 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 ?

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

Leave a Comment