id
ids and group membershipid shows who a user is as the kernel sees them: a user id, a group id, and a list of groups. Permissions are decided by these numbers, so when access is denied, this is where to look.
"Permission denied" on a group-readable file? id tells you whether you are in the group.
At the terminal
Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.
What the numbered lines are telling you
User id 1000, primary group 1000, and membership of sudo and docker. Each number is shown with its name.
The web server’s account has a low id and belongs only to its own group — as little access as possible.
The kernel grants root’s powers to id 0, whatever the account is called.
-n prints names instead of numbers and -G lists all groups: a compact answer to "what groups am I in?"
Switches
A switch changes how the command behaves. These are the ones used day to day; man id lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.
-u- Print only the user id.
-g- Print only the primary group id.
-G- Print every group id.
-n- With -u, -g or -G, print names instead of numbers.
-r- Print the real id rather than the effective one.
Variations worth knowing
The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.
groupsLists your group names — the same as id -nG.
getent passwd userShows a user’s account record: id, home directory and shell.
getent group dockerLists the members of a group.
newgrp dockerStarts a shell with a newly added group active, without logging out.
In cybersecurity
Group membership is where privilege hides in plain sight.
Members of sudo or wheel can become root. Members of docker, disk or lxd can too, by less obvious routes. Review who is in them.
A second account with user id 0 is a second root, whatever its name. There should be exactly one.
Adding a user to a group does not affect sessions already open — and removing them does not either, until those sessions end.