Users, Groups and sudo
Overview
Linux separates identity from permissions. A user represents a person or service. A group bundles users for common access. sudo lets an authorized user run one command with another user's privileges, usually root.
Detailed Notes
Inspect the current identity
whoami
id
groups
whoamiprints the effective user name.idprints UID, GID and group memberships.groupsprints groups for the current user.
Example output may look like:
uid=1000(learner) gid=1000(learner) groups=1000(learner),27(sudo)
The UID is an integer identity. The GID identifies the primary group.
The root account
Root is the privileged administrative identity. It can change system configuration and often bypass normal file permissions. Use root only for the specific action that requires it.
sudo -l
sudo id
sudo -l lists allowed administrative commands. sudo id runs id as root and prints the root identity. sudo may ask for the user's password, not the root password.
Switch to a shell carefully
sudo -i
exit
sudo -i starts a root login shell. exit returns to the previous shell. Avoid leaving a root shell open.
Basic account commands
sudo useradd -m appuser
sudo passwd appuser
sudo usermod -aG docker appuser
id appuser
-mcreates a home directory.passwdassigns a password.usermod -aGadds a group;-ameans append.
Practice account commands only in a disposable VM. On a workstation, adding users or groups can affect real access.
Common Interview Questions
Finished this lesson?
0 of 25 lessons done · 0% of the course

