To create a user on Linux, run sudo useradd -m -s /bin/bash deploy and then sudo passwd deploy: that makes the account with a home directory and a real shell, then sets its password. Below that, this page covers the rest of the account lifecycle: groups, listing users, changing a shell or password, and deleting a user cleanly.
Creating a user is an administrative task, so it runs as root (or with sudo):
sudo useradd -m -s /bin/bash deploy
sudo passwd deployHere it is for real:

What the useradd flags do
-mcreates the home directory (/home/deploy). On Debian and Ubuntu,useraddskips the home directory unless you pass-m, which breaks logins and dotfiles; on RHEL, Fedora, and Rocky it is created by default (CREATE_HOME yesin/etc/login.defs), so-mis a harmless no-op there. Pass-manyway: it is portable.useradditself is not idempotent, though: running it again for a username that exists fails with exit code 9, so automation should check first (id deployorgetent passwd deploy). This is the flag people forget.-s /bin/bashsets the login shell. Omit it and you get the distro default, which on some systems is/bin/shor even/usr/sbin/nologin.-G developers,dockeradds the user to extra (secondary) groups at creation.-c "Deploy Bot"sets the comment/full-name field.
After creating the account, list the users and groups on the system to 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.
| Command | What it is | Behavior |
|---|---|---|
useradd | The low-level binary, present on every Linux | Does exactly what you flag, nothing more. No home dir unless you pass -m, no password prompt. |
adduser | A 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:
sudo adduser deployIt 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.
Service accounts with no login
For a service account that should never log in directly, skip the password and give it no shell instead:
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.
Create a group on Linux
Groups are how Linux shares access between users. Creating one is a root task and a single command:
sudo groupadd developersThat adds a line to /etc/group. Confirm it with getent group:

A group on its own does nothing useful until it has members and owns (or is granted access to) some files. The point of a group is to let several users share access to the same resources without making those resources world-readable.
Add users to the group
Membership is set with usermod -aG, not groupadd, and the -a (append) is critical. The add a user to a group section below has the command, why dropping -a is dangerous, and how to verify and remove members.
Primary vs secondary groups
| Primary group | Secondary groups | |
|---|---|---|
| How many | Exactly one per user | Zero or more |
| Set with | useradd -g / usermod -g | useradd -G / usermod -aG |
| Used for | The group new files get by default | Extra access (docker, sudo, shared dirs) |
| Listed in | /etc/passwd (the GID field) | /etc/group member lists |
When deploy creates a file, it is owned by deploy's primary group. Adding deploy to developers as a secondary group lets it read and write developers-owned files, but new files it creates still belong to its primary group, unless the directory has the setgid bit.
A shared project directory, end to end
The common real task: a folder several people can work in.
sudo groupadd developers
sudo usermod -aG developers alice
sudo usermod -aG developers deploy
sudo mkdir /srv/project
sudo chown root:developers /srv/project
sudo chmod 2775 /srv/project # 2 = setgid: new files inherit the groupThe leading 2 (setgid) makes every file created in /srv/project belong to developers automatically. Group ownership is not the same as group write access, though: with the common 022 umask, a teammate's new file lands as 644 (rw-r--r--), and the rest of the group can read it but not edit it. For a directory the whole team edits, also give it a default ACL, which overrides the umask for new files inside it:
sudo setfacl -d -m g:developers:rwX /srv/project(Setting umask 002 for every member works too, but it applies to everything they create, everywhere.) Members must log out and back in (or run newgrp developers) for new group membership to take effect.
Add a user to a group
Adding an existing user to a group is one root command, and the flags matter more than the command:
sudo usermod -aG developers deploy
Never drop the -a
-G sets the user's secondary groups to exactly the list you give; -a makes it append instead of replace:
sudo usermod -aG developers deploy # CORRECT: adds developers, keeps the rest
sudo usermod -G developers deploy # DANGER: developers is now their ONLY secondary groupRun the second form and you have just removed deploy from sudo, docker, and every other group it was in. People lock themselves out of sudo this way constantly. Always -aG, never bare -G, unless you genuinely intend to replace the whole list.
Verify the membership, and the login catch
groups deploy # what the system says deploy is in
id deploy # same, with UIDs/GIDsGroup membership is read at login. A user already logged in does not gain the new group in their current session; they must log out and back in. To pick it up without logging out, start a shell with the group active using newgrp developers. The same applies to your own session, which is why Docker socket access often needs a fresh login after you add yourself to docker.
Add or remove with gpasswd
gpasswd works from the group's side and is handy in scripts:
sudo gpasswd -a deploy developers # add deploy to developers
sudo gpasswd -d deploy developers # remove deploy from developersgpasswd -a is equivalent to usermod -aG for a single group, and gpasswd -d is the clean way to remove someone from a group, which usermod cannot do directly (its only route is re-setting the full list with -G, which is error-prone).
List users and groups on Linux
The user and group databases are plain files, so listing them needs no special tool and no root. Read them with getent, which also covers users defined in LDAP or other directory backends, not just /etc/passwd:
getent passwd # every user
getent group # every group
cat /etc/passwd only shows local accounts; getent passwd queries the full Name Service Switch stack configured in /etc/nsswitch.conf. On a standalone box the output is the same, on a managed fleet it is not.
Just the usernames
The first colon-separated field of each line is the name:
getent passwd | cut -d: -f1 # all usernames
getent group | cut -d: -f1 # all group namescut -d: -f1 splits on the colon and keeps field one. (For more on slicing columns, see grep and print a specific column.)
Human accounts vs system accounts
Most entries in /etc/passwd are system accounts (daemon, www-data, sshd), not people. They are separated by UID. On most distros, regular human accounts start at UID 1000:
# Real login users (UID >= 1000, excluding nobody at 65534)
getent passwd | awk -F: '$3 >= 1000 && $3 < 65534 {print $1}'The third field ($3) is the UID. That one-liner lists the accounts in the regular-user UID range, which is the useful first cut at "which of these are people". It does not prove an account can log in: a UID 1000+ account can still have a nologin shell, a locked password, or be blocked by SSH or PAM rules, so check the shell (the last field) and the account's lock state separately. (awk -F: sets the field separator to a colon.)
Which groups is one user in?
groups deploy # group names for one user
id deploy # names plus UIDs and GIDs
getent group developers # the reverse: members are the last colon fieldgetent group lists only secondary members, not users whose primary group it is, so cross-check with id username.
Change a user's login shell
The login shell is the last field of a user's /etc/passwd line. Change another user's shell as root with chsh -s:
sudo chsh -s /usr/bin/zsh deploy
Changing your own shell needs no sudo: run chsh -s /usr/bin/zsh without a username and it prompts for your password. usermod does the same thing as root and is the scriptable choice:
sudo usermod -s /usr/bin/zsh deployThe change takes effect at the next login, not in the current shell. To try a shell right now without making it permanent, just run it: zsh.
The shell has to be in /etc/shells
For an ordinary user changing their own shell, chsh only accepts shells listed in /etc/shells. If yours is missing, chsh refuses it:
cat /etc/shells # the allowed login shells
which zsh # where the shell actually isIf zsh is installed but not listed, add its path to /etc/shells (as root) and chsh will then accept it. Root is not held to the same rule: sudo chsh at most warns about an unlisted shell rather than refusing it, so listing the shell properly is still the safe habit. usermod -s does not enforce /etc/shells, which is a footgun: it will happily set a path that does not exist and lock the user out of logging in. So prefer chsh interactively and usermod in automation where you control the value.
To read the current shell:
getent passwd deploy | cut -d: -f7 # the shell field for one user
echo "$SHELL" # your own current login shellSetting the shell to /usr/sbin/nologin (as in the service account above) is also part of locking an account fully.
Change a user password on Linux
To change your own password, run passwd with no arguments and no sudo. It asks for your current password, then the new one twice. To change another user's password you need root:
sudo passwd deploy
Root skips the rules; users don't
When you change your own password, passwd enforces the system policy: minimum length, complexity, not reusing the old one. When root sets a password, it can override all of that, which is why sudo passwd deploy never prompts for the user's old password and will accept a weak one with only a warning. That is by design: an admin resetting a forgotten password should not be blocked by the policy.
Force a reset, check status, lock
After an admin reset, you usually want the user to pick their own password immediately:
sudo passwd -e deploy # expire now; prompt at next login
sudo passwd -S deploy # status: P usable, L locked, NP no password
sudo passwd -l deploy # lock the password
sudo passwd -u deploy # unlockThere is a dedicated guide to forcing a change, including the chage -d 0 equivalent. Note that passwd -l locks the password only; an SSH key still works. For a full lockout see lock and unlock a user account.
Set a password non-interactively
For automation, pipe it through chpasswd rather than trying to script the interactive prompt:
echo 'deploy:S3cret-pass' | sudo chpasswdUseful in provisioning, but the password lands in shell history and process listings, so prefer SSH keys for anything that matters and reserve this for throwaway environments.
Delete a user on Linux
Deleting a user is a root task. The decision is whether to keep their files. To remove the account and its home directory and mail spool:
sudo userdel -r deploy
Without -r, userdel deploy removes the account but leaves /home/deploy behind. That is sometimes what you want (keep their work, free the login), but more often it just leaves orphaned files owned by a now-missing UID.
Before you delete: processes and shared files
A user can own files and processes all over the system, not just in their home directory. Deleting the account leaves those owned by a bare numeric UID, which a future new user could inherit.
# First, check: are they logged in or running anything?
who | grep deploy
ps -u deploy
# Then, if you are sure, end their processes
sudo pkill -u deploy
# Find everything they own outside their home
sudo find / -user deploy -not -path '/proc/*' 2>/dev/nulluserdel refuses to remove a user who is currently logged in or has running processes, which is a feature; check with who/ps, then end the processes first (or use userdel -f to force, which is riskier). The find sweep is the step people skip and regret. Reassign (chown) or remove what it finds before (or after) deleting the account. The owner-search syntax is covered in find files by owner and permission.
Lock instead of delete
For a departing team member, deleting the account immediately can break cron jobs, mail, and file ownership. Locking it keeps everything in place while blocking access:
sudo usermod -L deploy # lock the password
sudo usermod -s /usr/sbin/nologin deploy # block the shell tooYou get an audit trail and the option to reverse it. See lock and unlock a user account for the full set. Delete only once you are sure nothing depends on the account.
Remove the group too, if it was theirs
When USERGROUPS_ENAB is yes in /etc/login.defs (the usual setting on mainstream distros), userdel also deletes the user's private group, the one with the same name as the user, as long as it has no other members and is not another user's primary group (otherwise it warns and keeps it). A shared group the user merely belonged to always stays. To remove a now-empty group:
sudo groupdel developersFAQ
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.
-a means append. usermod -aG developers deploy adds developers to the user's existing secondary groups. Without -a, usermod -G replaces all secondary groups with just the one you named, which can remove the user from sudo, docker, and others.
Use sudo gpasswd -d deploy developers. usermod has no direct remove option; the workaround is to re-set the full group list with usermod -G, which is error-prone, so gpasswd -d is the safer choice.
Group membership is read at login, so the user must log out and back in (or run newgrp developers) for a new group to take effect in their session. Also confirm the files are actually group-owned by that group and group-readable.
The shell's path is not in /etc/shells. Confirm where it is with which zsh, then add that exact path to /etc/shells as root. For ordinary users, chsh only accepts shells listed there.
Because root is allowed to reset any password without knowing the current one, which is the whole point of an admin reset. Changing your own password with plain passwd does require the old one and enforces the complexity policy; root bypasses both.
userdel deploy removes the account but leaves the home directory and mail spool on disk. userdel -r deploy also deletes /home/deploy and the mail spool. Use -r for a clean removal; omit it if you want to keep their files.
userdel refuses to delete a logged-in user or one with running processes. End them first: sudo pkill -u deploy, confirm with who and ps -u deploy, then re-run userdel -r.
See also
- How to Give a User sudo Access: make the new account an admin.
- Lock and unlock a user account: the safer alternative to deletion.
- Set password expiry and account aging: max age, warnings, and account expiry.
- setuid, setgid, and the sticky bit: make shared directories keep their group.
- Find files by owner, group, or permission: track down what a user owns before removing them.
- How to Disable Root Login on Linux: once a real admin account exists, lock down direct root access.
- How to Schedule a Cron Job: put the new service account's tasks on a recurring timer.
Sources
Authoritative references this article was fact-checked against.
- useradd(8) - Linux manual page (man7.org)man7.org
- adduser(8) - Debian manual pagemanpages.debian.org
- userdel(8) - Linux manual page (man7.org)man7.org
- usermod(8) - Linux manual page (man7.org)man7.org
- groupadd(8) - Linux manual page (man7.org)man7.org
- group(5) - Linux manual page (/etc/group)man7.org
- getent(1) - Linux manual page (man7.org)man7.org
- passwd(5) - Linux manual page (/etc/passwd)man7.org
- chsh(1) - Linux manual page (man7.org)man7.org
- shells(5) - Linux manual page (/etc/shells)man7.org
- passwd(1) Linux manual page (man7.org)man7.org
- umask(2) manual pageman7.org





