Tools › Cheat sheets › System Administration › Users & groups
👥

Users & groups cheat sheet

Account and ownership commands for Linux. Most need sudo. On Debian/Ubuntu the admin group is sudo; on RHEL-family systems it is wheel.

Click any command to copy it.

Who am I and who is here

CommandWhat it does
whoamiShow the current user.
idShow UID, GID and groups.
groups userList a user's groups.
whoWho is logged in.
wWho is logged in and what they are doing.
lastRecent logins.
sudo -lList what you are allowed to run with sudo.

Create and modify users

CommandWhat it does
sudo adduser nameCreate a user interactively (Debian/Ubuntu).
sudo useradd -m -s /bin/bash nameCreate a user with a home directory and shell.
sudo passwd nameSet or change a password.
sudo usermod -aG groupname nameAdd a user to a group (the -a matters!).
sudo usermod -L nameLock an account.
sudo usermod -U nameUnlock an account.
sudo chage -l nameShow password ageing information.
sudo userdel -r nameDestructive: Delete a user and their home directory.
sudo chsh -s /bin/zsh nameChange a user's login shell.

Groups

CommandWhat it does
sudo groupadd groupnameCreate a group.
sudo gpasswd -d name groupnameRemove a user from a group.
getent group groupnameShow a group and its members.
getent passwd nameShow a user's account entry.
newgrp groupnameSwitch your active group for this shell.

Ownership

CommandWhat it does
sudo chown user:group fileChange owner and group.
sudo chown -R user:group dir/Destructive: Change ownership recursively; a wrong path can break a system.
sudo chgrp group fileChange only the group.
chmod g+w fileGive the group write access.
sudo visudoEdit the sudoers file safely with syntax checking.
su - nameSwitch to another user with their environment.

Frequently asked questions

Why must I use -aG with usermod?

-G alone replaces the user's supplementary groups with the list you give. -aG appends, which is almost always what you want.

How do I give a user sudo rights?

Add them to the admin group: sudo usermod -aG sudo name on Debian/Ubuntu, or -aG wheel on RHEL-family systems. They must log in again.

More System Administration cheat sheets

⚙️ systemctl📜 journalctl📦 apt🎩 dnf / yum📊 Processes & performance💽 Disks & storage🔄 rsync⏱️ Cron expressionsAll System Administration cheat sheets →
Copied to clipboard