TechEarl

How to Create a User on Linux (useradd vs adduser)

Create a Linux user with useradd or adduser, give it a home directory, shell, and password, and understand the difference between the low-level and friendly commands.

Ishan Karunaratne⏱️ 4 min readUpdated
Share thisCopied
Create a Linux user with useradd or adduser, set the home directory, shell and password, and the difference between the two commands.

Creating a user is an administrative task, so it runs as root (or with sudo). The fastest correct command:

bash
sudo useradd -m -s /bin/bash deploy
sudo passwd deploy

The first line creates the account with a home directory and a real shell; the second sets its password. That is the whole job. Here it is for real:

Root terminal running useradd -m -s /bin/bash deploy, then id deploy showing uid 1002, and tail of /etc/passwd showing the new deploy account with its home directory and bash shell.
useradd -m gives the account a home directory; -s sets the login shell. id and /etc/passwd confirm it exists.

What the flags do

  • -m creates the home directory (/home/deploy). On Debian and Ubuntu, useradd skips the home directory unless you pass -m, which breaks logins and dotfiles; on RHEL, Fedora, and Rocky it is created by default (CREATE_HOME yes in /etc/login.defs), so -m is a harmless no-op there. Pass -m anyway: it is portable and idempotent. This is the flag people forget.
  • -s /bin/bash sets the login shell. Omit it and you get the distro default, which on some systems is /bin/sh or even /usr/sbin/nologin.
  • -G developers,docker adds the user to extra (secondary) groups at creation.
  • -c "Deploy Bot" sets the comment/full-name field.

useradd vs adduser

This is the part that confuses people, because both exist and do similar things.

CommandWhat it isBehavior
useraddThe low-level binary, present on every LinuxDoes exactly what you flag, nothing more. No home dir unless you pass -m, no password prompt.
adduserA friendly Perl/shell wrapper (Debian/Ubuntu)Interactive: creates the home dir, copies /etc/skel, and prompts for a password and details.

On Debian and Ubuntu, adduser deploy is the nicer interactive path:

bash
sudo adduser deploy

It walks you through the password and finger info and sets up the home directory for you. On RHEL, Fedora, Arch, and Alpine, adduser may be missing or just a symlink to useradd, so useradd -m is the portable choice. When in doubt, use useradd -m -s /bin/bash and set the password separately; it works everywhere.

Give it a password (or don't)

bash
sudo passwd deploy                 # set an interactive login password

For a service account that should never log in directly, skip the password and give it no shell instead:

bash
sudo useradd -r -s /usr/sbin/nologin appsvc

-r makes it a system account (low UID, no aging), and nologin blocks interactive logins while still letting services run as that user.

FAQ

See also

Sources

Authoritative references this article was fact-checked against.

TagsLinuxuseraddadduserUser ManagementSystem Administration

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Tech Architect · Software Engineer · AI/DevOps

Tech architect and software engineer with 20+ years building software, Linux systems, and DevOps infrastructure, and lately working AI into the stack. Currently Chief Technology Officer at a healthcare tech startup, which is where most of these field notes come from.

Keep reading

Related posts