Privacy Policy
© 2025 linux101.dev

User and Group Management

A cheatsheet for common commands used to create, modify, and delete user accounts and groups.

Creating Users and Groups

Add a new user

sudo useradd [username]

Adds a new user to the system. The user will not have a home directory or a password set yet.

Add a user with a home directory

sudo useradd -m [username]

Creates a new user and automatically creates their home directory at `/home/[username]`.

Set a password for a user

sudo passwd [username]

Sets or changes the password for an existing user account. You will be prompted to enter the new password twice.

Add a new group

sudo groupadd [groupname]

Creates a new group.

Managing Users and Groups

Add a user to a group

sudo usermod -aG [groupname] [username]

Adds a user to a secondary group. The `-a` (append) flag is important so the user is not removed from other groups.

Delete a user

sudo userdel [username]

Deletes a user account but leaves their home directory and other files on the system.

Delete a user and their home directory

sudo userdel -r [username]

Deletes a user account and recursively removes their home directory and mail spool.

Delete a group

sudo groupdel [groupname]

Deletes a group. The group must be empty of members before it can be deleted.

Check a user's information

id [username]

Displays a user's UID, GID, and the groups they are a member of.