RH124 Ch 7: Permissions, umask and Special Bits
Each file has an owner, a group, and three permission sets: user (u), group (g), others (o).
| | file | directory | |---|---|---| | r (4) | read contents | list names | | w (2) | change contents | create/delete entries | | x (1) | run it | enter it / reach files inside |
Changing them - chmod 640 file or chmod u=rw,g=r,o= file; chmod -R for trees. - chown user:group file, chgrp group file.
Special bits - SGID on a directory (chmod 2770 / g+s): new files inherit the directory's group — ideal for team folders. - Sticky bit (chmod 1777 / o+t): in a shared writable directory users can delete only their own files (like /tmp). - SUID on a program (4755 / u+s): runs as the file's owner, e.g. /usr/bin/passwd. Find them with find / -perm -4000.
umask removes permissions from the defaults (666 files, 777 directories). umask 022 gives 644/755; 027 gives 640/750. Set it with umask 027; make it permanent in ~/.bashrc (one user) or a script in /etc/profile.d/ (everyone).
Diagnosing "Permission denied" 1. ls -l the file and ls -ld every directory above it — reaching a file needs x on each directory. 2. id user — is the user really in that group? (New group membership applies at the next login.) 3. Test as the user: su - user -c 'cat /path'. 4. Remember root ignores rwx, so testing as root proves nothing.
Exam traps: 777 is never the right answer; scripts need both r and x; SGID needs the group set as well as the bit.