How to Use the Linux useradd Command to Create New Users

When provisioning a new Linux server, relying exclusively on the root account is a catastrophic security vulnerability. Every human administrator and every automated background daemon (like a web server or database) must be mathematically isolated in its own dedicated user account with strictly limited permissions. While modern Ubuntu distributions offer the interactive adduser script, systems engineers writing automated Bash provisioning scripts rely on the low-level, non-interactive useradd command to construct user profiles.

Why Use the useradd Command?

The useradd command is a low-level POSIX binary that directly manipulates the system’s foundational security files (/etc/passwd, /etc/shadow, and /etc/group). Unlike the interactive adduser script (which prompts you with questions about passwords and phone numbers), useradd executes silently and mathematically. It takes all parameters as command-line flags. This makes it absolutely essential for automated Ansible playbooks, Dockerfile construction, or bash scripts where human interaction is impossible.

Step 1: Create a Standard User with a Home Directory

By default, useradd is extremely bare-bones. If you run it without flags, it will not create a home directory or assign a default shell.

  1. Open your Linux terminal. Because you are modifying system security files, you must use sudo.
  2. To create a complete user profile, you must use the -m (create home directory) and -s (specify shell) flags:
sudo useradd -m -s /bin/bash john_doe
  1. Press Enter. The command executes silently. It has mathematically injected john_doe into /etc/passwd, created /home/john_doe, and assigned the bash shell.

Step 2: Assign a Password

The user account now exists, but it is locked because it lacks a mathematical password hash.

  1. Run the passwd command to assign credentials to the new account:
sudo passwd john_doe
  1. The terminal will prompt you to type (and confirm) the new password. Once completed, the mathematical hash is injected into /etc/shadow, unlocking the account.

Step 3: Create a Headless System Account (Daemons)

When installing a new background service (like a custom Node.js application), it needs an account to run under. However, this account must never be allowed to log into the server.

  1. Use the -r (system account) and -s (shell) flags to mathematically lock out human interaction:
sudo useradd -r -s /usr/sbin/nologin node_app_user

This command creates a mathematical \”ghost\” account. It has no home directory, its User ID is mathematically placed in the reserved system range (typically under 1000), and its shell is hardcoded to nologin, meaning if a hacker tries to SSH into it, the kernel will instantly reject the connection.

By mastering the useradd command, Linux administrators can mathematically construct complex, secure, and isolated user environments entirely through headless automation.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.