Home Blog Certs Knowledge Base About

Permissions & ACL

Linux permission system: chmod (mode bits), chown (ownership), umask (default permissions), setfacl/getfacl (fine-grained ACL for multiple users and groups).

chmod

Octal mode
CommandSymbolicMeaning
chmod 755 filerwxr-xr-xOwner full, others read+execute
chmod 644 filerw-r--r--Owner read+write, others read
chmod 600 filerw-------Owner only (private key, secret file)
chmod 700 dirrwx------Owner only (private directory)
chmod 664 filerw-rw-r--Owner + group write, others read
chmod 777 filerwxrwxrwxEveryone full โ€” avoid unless intentional
Symbolic mode
CommandDescription
chmod u+x fileAdd execute for owner (u)
chmod g-w fileRemove write for group (g)
chmod o= fileRemove all permissions for others (o)
chmod a+r fileAdd read for all (a = u+g+o)
chmod ug+rw fileOwner and group read+write
chmod -R 755 /var/wwwRecursive โ€” dangerous if mixed files/dirs
find /var/www -type f -exec chmod 644 {} +Safer: set 644 on files only
find /var/www -type d -exec chmod 755 {} +Set 755 on directories only
Special bits
CommandOctalEffect
chmod u+s /usr/bin/ping4755SUID โ€” runs as file owner (root for ping)
chmod g+s /shared/dir2755SGID โ€” new files in dir inherit the group
chmod +t /tmp1777Sticky โ€” only file owner can delete (shared dirs)
chmod 4755 file4755SUID + rwxr-xr-x in one octal
Permission bits reference
OctalBinarySymbolic
7111rwx
6110rw-
5101r-x
4100r--
3011-wx
2010-w-
1001--x
0000---

chown

chown commands
CommandDescription
chown alice fileChange owner to alice
chown alice:staff fileChange owner and group
chown :staff fileChange group only
chgrp staff fileChange group only (alternative)
chown -R alice:alice /home/aliceRecursive ownership change
chown --reference=ref_file targetCopy ownership from another file

umask

umask โ€” default permissions
umaskNew filesNew dirsUse case
022644 (rw-r--r--)755 (rwxr-xr-x)Default โ€” others can read
027640 (rw-r-----)750 (rwxr-x---)Group read, no others
077600 (rw-------)700 (rwx------)Private โ€” owner only
002664 (rw-rw-r--)775 (rwxrwxr-x)Collaborative โ€” group can write

umask subtracts from maximum: files start at 666, dirs at 777. umask 022 โ†’ 666 - 022 = 644 for files, 777 - 022 = 755 for dirs.

umask          # show current umask
umask 027      # set for current shell
umask -S       # symbolic form: u=rwx,g=rx,o=

Set system-wide default in /etc/login.defs (LOGIN_UMASK) or /etc/profile.

setfacl / getfacl

ACL โ€” extended permissions
CommandDescription
getfacl fileShow all ACL entries for a file
setfacl -m u:alice:rw fileGive alice read+write
setfacl -m u:bob:r-- fileGive bob read-only
setfacl -m u:carol:--- fileExplicitly deny carol
setfacl -m g:devs:rwx dirGive group devs full access
setfacl -m o::r-- fileSet other ACL entry
setfacl -x u:alice fileRemove alice's ACL entry
setfacl -b fileRemove all ACL entries (reset to standard)
setfacl -R -m u:alice:rX dirRecursive: read + conditional execute (X = dirs only)
setfacl -d -m u:alice:rw dirDefault ACL โ€” inherited by new files in dir
setfacl -d -m g:devs:rwx dirDefault ACL for group
setfacl -k dirRemove only default ACL
getfacl dir1 | setfacl --set-file=- dir2Copy ACL from one dir to another
getfacl -R /data > acl_backup.txtBackup ACLs recursively
setfacl --restore=acl_backup.txtRestore backed up ACLs
ACL entry format
EntryMeaning
u::rwxOwner permissions
u:alice:rw-Named user alice
g::r-xOwning group permissions
g:devs:rwxNamed group devs
m::rwxEffective rights mask (limits named users/groups)
o::r--Other (everyone else)
d:u:alice:rw-Default ACL entry (prefix d:)

A + at the end of ls -l output means ACL is present. The mask (m) limits the effective permissions of named users and groups โ€” getfacl shows both the entry and #effective: if the mask reduces it.

Requirements: filesystem must be mounted with ACL support. On ext4 it’s enabled by default. Check: tune2fs -l /dev/sda1 | grep "Default mount".