# useradd — Create and Manage User Accounts on Linux

> Practical guide to useradd, usermod and userdel — create, modify and delete Linux user accounts, home directories, groups and passwords safely.

Source: https://www.jpkc.com/db/en/cheatsheets/shell-system/useradd/

<!-- PROSE:intro -->
useradd is the low-level standard tool for creating Linux user accounts directly – without `-m` it leaves no home directory, and without a follow-up `passwd` the account stays locked. On Debian and Ubuntu the friendlier `adduser` wrapper handles those steps interactively and applies sensible defaults. Together with `usermod`, `userdel`, `passwd` and the group commands you manage accounts, shells and group memberships. Almost every one of these actions needs `sudo` and reaches deep into the system.
<!-- PROSE:intro:end -->

## Create Users

`useradd <user>` — Create a new user (minimal, no home directory on some distros).

```bash
sudo useradd john
```

`useradd -m <user>` — Create a user with a home directory.

```bash
sudo useradd -m john
```

`useradd -m -s <shell> <user>` — Create a user with a specific login shell.

```bash
sudo useradd -m -s /bin/bash john
```

`useradd -m -G <groups> <user>` — Create a user and add to supplementary groups.

```bash
sudo useradd -m -G sudo,docker john
```

`useradd -r -s /usr/sbin/nologin <user>` — Create a system user (no login, for services).

```bash
sudo useradd -r -s /usr/sbin/nologin appuser
```

`useradd -m -c '<comment>' <user>` — Create a user with a full name/comment.

```bash
sudo useradd -m -c 'John Doe' john
```

## Modify Users

`usermod -aG <group> <user>` — Add a user to a group (append, keep existing groups).

```bash
sudo usermod -aG docker john
```

`usermod -s <shell> <user>` — Change a user's login shell.

```bash
sudo usermod -s /bin/zsh john
```

`usermod -l <newname> <oldname>` — Rename a user account.

```bash
sudo usermod -l johndoe john
```

`usermod -d <dir> -m <user>` — Change home directory and move files.

```bash
sudo usermod -d /home/johndoe -m john
```

`usermod -L <user>` — Lock a user account (disable login).

```bash
sudo usermod -L john
```

`usermod -U <user>` — Unlock a user account.

```bash
sudo usermod -U john
```

## Delete Users

`userdel <user>` — Delete a user (keep home directory).

```bash
sudo userdel john
```

`userdel -r <user>` — Delete a user and remove home directory.

```bash
sudo userdel -r john
```

## Passwords

`passwd <user>` — Set or change a user's password.

```bash
sudo passwd john
```

`passwd -l <user>` — Lock a user's password.

```bash
sudo passwd -l john
```

`passwd -u <user>` — Unlock a user's password.

```bash
sudo passwd -u john
```

`passwd -e <user>` — Expire password (force change on next login).

```bash
sudo passwd -e john
```

`chage -l <user>` — Show password aging information.

```bash
sudo chage -l john
```

`chage -M <days> <user>` — Set maximum password age in days.

```bash
sudo chage -M 90 john
```

## Groups

`groupadd <group>` — Create a new group.

```bash
sudo groupadd developers
```

`groupdel <group>` — Delete a group.

```bash
sudo groupdel developers
```

`groups <user>` — Show all groups a user belongs to.

```bash
groups john
```

`gpasswd -a <user> <group>` — Add a user to a group.

```bash
sudo gpasswd -a john docker
```

`gpasswd -d <user> <group>` — Remove a user from a group.

```bash
sudo gpasswd -d john docker
```

`getent group <group>` — Show members of a group.

```bash
getent group docker
```

## Info & Listing

`id <user>` — Show user UID, GID, and group memberships.

```bash
id john
```

`whoami` — Show the current username.

```bash
whoami
```

`getent passwd <user>` — Show user account details from passwd database.

```bash
getent passwd john
```

`cat /etc/passwd | grep <user>` — Look up a user in the passwd file.

```bash
cat /etc/passwd | grep john
```

`last <user>` — Show last login times for a user.

```bash
last john
```

<!-- PROSE:outro -->
## Conclusion

For everyday work a handful of commands suffice: `useradd -m` creates a full account with a home directory, `passwd` sets the first password, and `usermod -aG` appends group memberships. That last one hides the most common trap – forget the `-a` and `usermod -G` replaces all existing supplementary groups instead of adding to them. Keep in mind that membership in `sudo` or `docker` effectively grants root-equivalent privileges and should be handed out deliberately. And `userdel -r` wipes the entire home directory along with all its data – without asking.

## Further Reading

- [Arch Wiki: Users and groups](https://wiki.archlinux.org/title/Users_and_groups) – thorough reference on Linux account and group management
- [Debian Wiki: UserManagement](https://wiki.debian.org/UserManagement) – managing users and groups on Debian-based systems
<!-- PROSE:outro:end -->

## Related Commands

- [su](https://www.jpkc.com/db/en/cheatsheets/shell-system/su/) – switch to another user or to root
- [sudo](https://www.jpkc.com/db/en/cheatsheets/shell-system/sudo/) – run individual commands with elevated privileges
- [id](https://www.jpkc.com/db/en/cheatsheets/shell-system/id/) – show a user's UID, GID and group memberships

