whoamiWhich user you are right now.
Cheat sheet
Adding and removing accounts, managing groups, locking someone out properly, and who's allowed to sudo.
Nothing you type here is sent. Nothing is saved, unless you switch on Remember. Privacy policy
These work the same on Debian, Ubuntu, Fedora, Rocky and RHEL, except where a section says otherwise. Anything that
changes an account needs sudo.
Nothing matches that. Try fewer words, or a shorter one.
whoamiWhich user you are right now.
id deployA user's ID number, their main group, and every group they're in.
getent passwd deployThe account's details: user ID, home folder and login shell. Also works for accounts that come from LDAP or Active Directory.
getent group developersA group's ID and who's in it.
wWho's logged in right now, and what they're running.
last -n 20The last 20 logins, with where they came from.
sudo useradd -m -s /bin/bash deployCreate a user, with a home folder and a proper shell. Works everywhere.
-m-ssh)sudo adduser deployThe friendlier way on Debian and Ubuntu: it makes the home folder and asks for a password as it goes.
sudo passwd deploySet or change a user's password.
sudo usermod -s /usr/sbin/nologin deployStop someone getting a shell, while the account still exists (for service accounts).
sudo userdel deployDelete an account, but leave their home folder and files where they are.
sudo userdel -r deployDelete an account and their home folder. Back up anything you might want first.
-rsudo chage -E 0 deploySwitch an account off completely, SSH keys included. The reliable way to lock someone out.
-E 0sudo chage -E -1 deploySwitch it back on.
sudo passwd -l deployLock the password only. Careful: they can still log in with an SSH key.
sudo passwd -u deployUnlock the password again.
sudo faillock --user deploy --resetClear failed login attempts after someone's been locked out for typing the wrong password too often (on systems using pam_faillock, like RHEL and Rocky).
sudo groupadd developersCreate a group.
sudo usermod -aG developers deployAdd a user to a group. It takes effect the next time they log in.
-a-Gsudo gpasswd -d deploy developersTake a user out of a group.
newgrp developersUse a group you were just added to, without logging out and back in.
sudo groupdel developersDelete a group (its members keep their accounts).
sudo -lWhat you're allowed to run with sudo.
sudo -l -U deployWhat someone else is allowed to run with sudo.
sudo usermod -aG sudo deployMake someone an admin on Debian and Ubuntu.
sudo usermod -aG wheel deployMake someone an admin on Fedora, Rocky and RHEL.
sudo visudo -f /etc/sudoers.d/deployGive someone a narrower sudo rule in its own file. visudo checks the syntax before saving, so a typo can't lock everyone out of sudo. A line like deploy ALL=(root) NOPASSWD: /usr/bin/systemctl restart nginx allows exactly one command.
sudo chage -l deployWhen the password was last changed, and when it (or the account) expires.
sudo chage -M 90 deployMake the password expire after this many days.
-Msudo passwd -e deployMake them choose a new password the next time they log in.
sudo install -d -m 700 -o deploy -g deploy /home/deploy/.sshMake a user's .ssh folder with the ownership and permissions SSH insists on.
-d-m 700-o-gsudo install -m 600 -o deploy -g deploy key.pub /home/deploy/.ssh/authorized_keysInstall their public key (key.pub) as the one key that can log in as them. This replaces any keys already there.