ubuntu, updated

Special permissions and ACLs

setgid, sticky bit, setuid, umask and ACLs: what they do and when you need them.

Special bits

Three extra bits on top of rwx. They show up in place of the x in ls -l.

BitOctalOn a directoryOn a fileShows as
setgid2000New files get the directory’s group (not the creator’s)Runs with the file’s grouprwxrws---
sticky1000Only the owner of a file may delete it(no effect)rwxrwxrwt
setuid4000(no effect)Runs as the file owner (e.g. passwd runs as root)rwsr-xr-x
sudo chmod g+s /srv/shared      # setgid on a shared folder (most useful one)
sudo chmod +t /srv/dropbox      # sticky: like /tmp
sudo chmod 2770 /srv/shared     # setgid + rwxrwx---, in one go

setgid on shared folders is the one you’ll actually use, see Permission best practices. Don’t set setuid on your own scripts. Find all setuid files with sudo find / -perm -4000 -type f 2>/dev/null.

umask: default permissions

The umask removes rights from new files. Ubuntu’s default is 002 for normal users, so new files are 664 and directories 775 (group may write; that works because every user has a private group).

umaskFilesDirectories
002 (Ubuntu default)664775
022644755
027640750
077600700

Check with umask. Set it for a service with UMask=0027 in its systemd unit, for users in ~/.bashrc.

ACLs: more than one group

Normal permissions allow exactly one owner and one group. ACLs (Access Control Lists) add rights for extra users and groups on the same file. Ubuntu’s ext4 and XFS support them out of the box. Tools: sudo apt install acl if setfacl is missing.

WhatCommand
Show ACLsgetfacl /srv/shared
Give user ben read + writesetfacl -m u:ben:rw file
Give group auditors read on a foldersetfacl -R -m g:auditors:rX /srv/shared
Default ACL: also for new filessetfacl -R -d -m g:auditors:rX /srv/shared
Remove one entrysetfacl -x u:ben file
Remove all ACLssetfacl -b file

A + at the end of the rights in ls -l (drwxrws---+) means the file has ACLs. chmod on such a file changes the ACL mask, which can quietly limit what the ACL entries allow. If an ACL “doesn’t work”, look at the mask:: line in getfacl.

Tip: Use ACLs when one group really isn’t enough. If you can solve it with a group and setgid, do that, it is easier to understand later.

§ home
~/knubertus/home/
1,1 Top