Chapter 7: Permissions and ACLs

Linux permissions and ACLs cheat sheet

The chapter on one page: what to remember, the commands to have at your fingertips, and flashcards for quick revision.

The chapter in eight sentences

Cheat sheet

Reading

CommandDoes
ls -l, ls -ld DIRPermissions of files, or of a directory itself
stat -c "%A %a %U:%G %n" FSymbols, octal, owner, group
id [USER]Who you are, and your groups
namei -l PATHPermissions of every directory on the way
getfacl FFull ACL, with the mask and effective access

Changing

CommandDoes
chmod 640 FSet the mode with numbers
chmod u=rw,g=r,o= FSet the mode with symbols
chmod g+w F, chmod o-r FChange one thing
chmod -R u=rwX,g=rX,o= DIRRecursive, without making files executable
chown USER:GROUP F, chgrp GROUP FChange owner, group
umask 027Defaults for new files (640) and directories (750)

Special and ACL

CommandDoes
chmod 2770 DIR, chmod g+s DIRsetgid: new files inherit the group
chmod 1777 DIR, chmod +t DIRsticky: delete only your own
find /usr -perm -4000List setuid programs
setfacl -m u:NAME:r FAdd or change a named entry
setfacl -m g:NAME:rX DIRSame for a group; X = directories only
setfacl -d -m u:NAME:r DIRDefault ACL for new files
setfacl -x u:NAME F, setfacl -b FRemove one entry, all entries

Flashcards

What do r, w and x mean on a regular file?
Read the contents, change them, run the file as a program.
What do r, w and x mean on a directory?
List the names, create/delete/rename entries (needs x too), and enter it or reach files by name.
Which permission class applies when you own the file and are also in its group?
The owner class only. The first match wins.
Octal values of r, w, x?
r = 4, w = 2, x = 1. Add them per class.
Set a file to rw-r-----, two ways?
chmod 640 file; chmod u=rw,g=r,o= file
Make directories enterable in a recursive change without making files executable?
chmod -R u=rwX,g=rX,o= tree (capital X)
Change owner and group in one command?
chown user:group file
What does umask 027 do to new files and directories?
Files 666 → 640, directories 777 → 750.
Shared directory whose files belong to the team group?
chgrp team dir; chmod 2770 dir (setgid)
Which bit stops users deleting each other's files in a shared directory?
The sticky bit: chmod +t dir (mode 1777 for /tmp).
Give john read access without changing owner or group?
setfacl -m u:john:r-- file; read it with getfacl file
Make new files in a directory inherit an ACL?
A default ACL: setfacl -m d:u:john:r-- dir