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.

After creating the account, listing the users and groups on the system with getent passwd, id, and /etc/group is how you confirm the UID, home directory, and group memberships landed the way you intended.

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

useradd is the low-level command on every Linux and does only what you tell it (you must pass -m for a home directory). adduser is a friendly interactive wrapper on Debian/Ubuntu that creates the home directory, copies skeleton files, and prompts for a password. For portability across distros, use useradd -m.

You ran useradd without -m. Either recreate with useradd -m, or create it after the fact: sudo mkdir /home/deploy && sudo chown deploy:deploy /home/deploy. The adduser wrapper always makes the home directory.

For a service account, skip passwd and set a non-login shell: sudo useradd -r -s /usr/sbin/nologin appsvc. The account exists and can own files and run services, but nobody can log in as it interactively. Add an SSH key to authorized_keys if it needs key-based access.

See also

Sources

Authoritative references this article was fact-checked against.

TagsLinuxuseraddadduserUser ManagementSystem Administration

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Software Systems Architect · Senior Software Engineer · Engineering Leadership

Software systems architect and senior software engineer with more than two decades designing, building, and running production software, Linux systems, and DevOps infrastructure, and lately working AI into the stack. Now a CTO, though what I write here is drawn from the full arc of that work, across architecture, engineering, and operations, not any single job.

Keep reading

Related posts