Chapter 6: Users and groups

Linux users and groups cheat sheet

The chapter on one page: what to remember, the commands to have at your fingertips, and flashcards for quick revision.

The chapter in eight sentences

Cheat sheet

Accounts

CommandDoes
id USERUID, primary group and groups
useradd [-u UID] [-g GROUP] [-G G1,G2] [-c TEXT] [-s SHELL] NAMECreate an account
usermod -aG GROUP NAMEAdd a supplementary group
usermod -c TEXT, -s SHELL, -L, -UComment, shell, lock, unlock
userdel -r NAMEDelete with home directory
groupadd [-g GID] NAME, groupmod -n NEW OLD, groupdel NAMEGroups
gpasswd -a USER GROUP, gpasswd -d USER GROUPAdd, remove a member

Passwords

CommandDoes
passwd [USER]Set a password
passwd -S USERStatus: LK locked, PS set, NP none
chage -l USERShow ageing as dates
chage -M 90 -m 1 -W 7 USERMax, min, warning
chage -d 0 USERChange at next login
chage -E YYYY-MM-DD USER, chage -E 0 USERExpire on a date, now
/etc/login.defsDefaults for new accounts

Root access

CommandDoes
su -Root login shell (root's password)
sudo CMD, sudo -iRun as root, root shell (your password)
sudo -lWhat you may run
%group ALL=(ALL) ALLGroup may run anything
user ALL=(ALL) /usr/bin/systemctlOne command, any arguments
NOPASSWD:Skip the password prompt
visudo -c, visudo -cf FILECheck syntax
/var/log/securesudo's record

Flashcards

Which UID is root, and where do regular users start?
Root is **0**; regular users start at **1000**.
Where are password hashes kept?
`/etc/shadow`, readable only by root.
Primary or supplementary group, which owns the files a user creates?
The **primary** group.
su - or sudo, whose password does each ask for?
`su -` asks for root's; `sudo` asks for your own.
Why is student allowed to use sudo in the lab?
It is in the **wheel** group, which `/etc/sudoers` allows to run any command.
Safe place and permissions for a new sudo rule?
A file in `/etc/sudoers.d`, mode **440**, checked with `visudo -c`.
Add bob to the docker group, keeping his other groups?
`usermod -aG docker bob`
Delete an account and its home directory?
`userdel -r NAME`
Force a password change at the next login?
`chage -d 0 NAME`
Make an account stop working on a date?
`chage -E YYYY-MM-DD NAME`
Lock or expire, which also blocks SSH keys?
**Expire** (`chage -E 0`). A lock only blocks the password.