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.

ADVERTISEMENTS

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

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
29 comments… add one
  • maruf Feb 21, 2009 @ 17:38

    thanks for your information.

  • digitalpbk May 17, 2009 @ 17:45

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

  • bug Mar 3, 2010 @ 8:20

    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 Feb 5, 2011 @ 0:04

      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 Dec 5, 2013 @ 20:26

      Do you even linux?

    • Aditya_A Mar 29, 2017 @ 5:52

      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?

  • newbee Apr 5, 2010 @ 15:49

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

  • PANYE Jun 3, 2010 @ 15:03

    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

  • An M Jun 26, 2010 @ 2:30

    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 Jun 24, 2011 @ 10:45

    How can i manage user from Command Line

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

  • Mangesh Sep 19, 2011 @ 7:54

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

    useradd -m user1 -p passwordforuser1

  • G8KeaPoR Dec 22, 2011 @ 16:28

    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 Nov 3, 2012 @ 20:58

      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 Feb 1, 2012 @ 19:13

    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 Apr 25, 2012 @ 14:39

    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

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

  • Ace Macleod Jul 19, 2012 @ 14:51

    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 –

    • big boy Nov 8, 2016 @ 10:29

      too late nerd haha

  • liang Nov 2, 2012 @ 8:55

    hi ,
    how about add user full name

  • nithya Dec 17, 2012 @ 9:04

    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

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

  • Sham kiran Dec 2, 2013 @ 4:59

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

  • tamnq Feb 28, 2014 @ 22:57

    how to su user basic to root permision

  • Andrei Mar 24, 2014 @ 23:30

    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 Mar 20, 2015 @ 13:15

    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 Nov 28, 2015 @ 5:52

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

  • jerin Feb 15, 2016 @ 8:48

    if i’m adding an user the system say “/etc/passwd” denied why

    • anke Jul 29, 2016 @ 18:36

      you need root access

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.