sodcalculator

10 Tech How-To

How to Create Users in Linux: Step-by-Step

Guide 10-57010 · Updated · Step by step

Creating user accounts is a basic but essential Linux administration task. This guide walks you through adding new users from the command line, setting their passwords, and assigning them to groups. You’ll learn the exact commands to run and what each one does, so you can confidently manage accounts on any Linux system.

What You’ll Need

  • A Linux system with a terminal (any distribution, e.g., Ubuntu, Debian, CentOS, Fedora).
  • Access to an account with sudo privileges (or the root password).
  • Basic familiarity with the command line.

Step-by-Step

  1. Open a terminal.

    On most desktop systems, you can press Ctrl+Alt+T or find “Terminal” in your applications menu. On a server, log in via SSH.

  2. Run the useradd command with sudo.

    The basic syntax is: sudo useradd username. Replace username with the desired login name (e.g., alice). This creates the user but does not set a password yet.

  3. Set a password for the new user.

    Use the passwd command: sudo passwd alice. You’ll be prompted to enter and confirm the password. Choose a strong one (at least 8 characters, mixing letters, numbers, and symbols).

  4. Verify the user was created.

    Check the account details with: id alice. This shows the user ID (UID), group ID (GID), and the groups the user belongs to. By default, a group with the same name as the user is created.

  5. Create a home directory (if not auto-created).

    On many distributions, useradd does not create a home directory by default. To create one and populate it with default files, use: sudo useradd -m alice. The -m flag creates the home directory at /home/alice.

  6. Set the user’s shell (optional).

    To specify a login shell (e.g., Bash), use: sudo useradd -m -s /bin/bash alice. If you omit this, the system default shell (usually /bin/sh) is used.

  7. Add the user to additional groups.

    If the user needs access to certain resources (like sudo for admin rights, or docker for container management), add them with: sudo usermod -aG sudo alice. The -aG flags append to the group list without removing existing groups.

  8. Test the new account.

    Log out of your current session and log in as the new user, or switch to them with: su - alice. This ensures the account works and the home directory is accessible.

Common Mistakes

  • Forgetting the -m flag – Without it, the user has no home directory, which can cause issues with many applications.
  • Not setting a password – A user without a password cannot log in. Always run passwd after creating the account.
  • Using usermod without -aG – If you omit -a, the user is removed from all groups not listed in the command, which can lock them out of essential permissions.
  • Creating duplicate usernames – Linux usernames must be unique. Check with id username before adding.

Tips

  • Use the adduser command on Debian/Ubuntu systems – it’s a friendlier wrapper that creates the home directory, sets the shell, and prompts for a password interactively.
  • Set an expiration date for temporary accounts with sudo chage -E 2025-12-31 alice.
  • To see all users on the system, view the /etc/passwd file: cat /etc/passwd.
  • Always use sudo instead of logging in as root when possible – it leaves an audit trail and reduces risk.

Troubleshooting

  • “useradd: command not found” – The command might not be in your PATH. Try the full path: /usr/sbin/useradd, or install the passwd package if on a minimal system.
  • “Permission denied” when running sudo – Your account may not have sudo rights. Log in as root (if you know the root password) or boot into recovery mode to fix sudoers.
  • User cannot log in – Check that the password is set and the account is not locked. Run sudo passwd -S alice to see status. If locked, unlock with sudo passwd -u alice.
  • Home directory not created – If you already created the user without -m, you can create the directory manually: sudo mkdir /home/alice and set ownership: sudo chown alice:alice /home/alice.

Frequently Asked Questions

What is the difference between useradd and adduser?

useradd is the low-level utility, while adduser is a Perl script that uses useradd but provides a more interactive, user-friendly experience, automatically creating the home directory and prompting for a password.

How do I delete a user?

Use sudo userdel -r username. The -r flag removes the user’s home directory and mail spool. Without -r, the home directory remains.

Can I create a user without a home directory?

Yes, simply omit the -m flag. This is sometimes done for system accounts that don’t need a home directory, like service accounts.

How do I change a user’s password after creation?

Run sudo passwd username and follow the prompts. You can also force the user to change it at next login with sudo chage -d 0 username.

What is a UID and why does it matter?

UID (User ID) is a numeric identifier for the user. The system uses it internally for permissions. Regular users typically have UIDs starting at 1000 (or 500 on some systems). You can specify a UID with sudo useradd -u 1500 alice.

How do I add a user to the sudo group?

On Debian/Ubuntu, use sudo usermod -aG sudo alice. On RHEL/CentOS/Fedora, use sudo usermod -aG wheel alice. The user must log out and back in for the change to take effect.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →