08 Permissions and Users
Learning objectives
- Inspect the current user identity and groups.
- Understand file read, write, and execute permissions.
- Use administrator privileges when required.
Command overview
| Command | Purpose | Meaning | Basic usage | Example |
|---|---|---|---|---|
whoami | Show the effective user | Displays the effective user of the current process | whoami | whoami |
id | Show user and group IDs | Displays UID, GID, and group membership | id [user_name] | id |
groups | Show groups | Displays groups of the current or named user | groups [user_name] | groups |
chmod | Change permissions | Change mode; changes read/write/execute permission | chmod permissions file | chmod u+x -- script.sh |
chown | Change ownership | Change owner; usually needs authorization; see syntax reference below | chown user:group file | chown -- USER:GROUP /absolute/path |
sudo | Change execution identity under policy | Runs a command as root or another user under sudoers policy | sudo [options] command | sudo -l |
su | Switch user | Substitute user; switches to another user | su user_name | su root |
passwd | Change a password | Sets a password for the current or named user | passwd [user_name] | passwd |
Common scenarios
Inspect the current identity:
whoami
id
groupsGive a script its owner execute permission:
chmod u+x -- run.sh
./run.shSet common file modes:
chmod 644 config.txt
chmod 755 script.shView sudo policy (authentication may be required):
sudo -lChanging ownership changes external state, so this is syntax reference only:
sudo chown -- USER:GROUP /absolute/pathNotes for beginners
- Linux modes commonly distinguish the file owner, group, and other users. ACLs, capabilities, and SELinux/AppArmor can add constraints.
rmeans read,wmeans write, andxmeans execute.- On a directory,
xmeans traverse/search directory entries, not “execute the directory.” Reading directory names normally also requiresr. chmod u+xexplicitly adds execute only for the owner. The result ofchmod +xwithout awhocan be affected by umask.644/755are common examples, not universal security answers. Secret files, shared directories, and service accounts need an actual access-model design.- What
sudocan run is determined by policy; it does not grant unlimited administrator authorization. Reconfirm before deletion, overwriting, or permission changes. - Do not operate as root long-term. When elevation is necessary, prefer
sudo.
A minimal intuition for numeric modes
r=4, w=2, and x=1. Adding each group produces the owner/group/other digits. For example, 640 means owner read/write, group read-only, and no permission for others. Inspect rather than memorize:
umask
stat --format='%A %a %U:%G %n' -- config.txt
namei -l -- "$PWD/config.txt"namei is part of util-linux and can be absent on a minimal system. It helps inspect directory traversal permission one component at a time.
Exercise without sudo
In your own lab directory, create run.sh and config.txt, then change only owner permissions:
chmod u+x,go-x -- run.sh
chmod u=rw,g=r,o= -- config.txt
stat --format='%A %a %U:%G %n' -- run.sh config.txtDo not recurse with chmod or chown. A real recursive change must verify the canonical absolute path, that owner/group exist, symbolic links, mount boundaries, and authorization.