Security and File Permissions
Domain 5 - Security and File Permissions
This domain tests account types, the files that define them, and the permission model that protects everything on disk - the highest-yield topic on the exam.
Core rules
root(UID 0) bypasses permission checks. Standard users have UID ≥ 1000; system accounts have low UIDs and usually no login shell.sudoruns one command as root;su -opens a root shell./etc/passwdholds username, UID, GID, home and shell;/etc/shadowholds the hashed password and is readable only by root;/etc/groupholds group membership.id,who,wandlastreveal who is logged in.useradd,groupadd,usermod -aGandpasswdmanage accounts;/etc/skelseeds each new home directory.ls -lshows a mode like-rwxr-x---: file type, then owner/group/other triples of r(4), w(2), x(1).chmod 750 fileyields rwxr-x---.chown user:group fileandchgrpchange ownership.umasksubtracts from defaults; 022 gives files 644 and directories 755.- SUID (
4xxx) runs a program as the file owner, SGID (2xxx) as the file's group, and the sticky bit (1xxx) on/tmpstops users deleting each other's files. - Hard links share an inode and cannot cross filesystems; symbolic links (
ln -s) store a path and can dangle.
Worked example
backup.sh must be executable and readable by all but writable only by its owner: chmod 755 backup.sh. Reasoning: 7 = rwx for owner, 5 = r-x for group, 5 = r-x for others; scripts also need read permission to be interpreted.
Traps
chmod 777as a universal fix - it grants world write.- Mode 644 on a directory removes the execute bit and breaks
cd. usermod -aGwithout-areplaces all supplementary groups.- Editing
/etc/shadowby hand instead of usingpasswd.