Skip to content
Linux

Permissions & Ownership

Manage read/write/execute bits with chmod and chown.

By EZ4Code Team
permissionchmodchown

Code

# Octal and symbolic modes
chmod 755 script.sh            # rwxr-xr-x
chmod 644 config.yml           # rw-r--r--
chmod u+x deploy.sh            # add execute for owner
chmod g-w,o-r secret.key       # remove group write, other read

# Recursively set dirs and files separately
find /var/www -type d -exec chmod 755 {} +
find /var/www -type f -exec chmod 644 {} +

# Ownership
chown alice:devs file.txt
chown -R alice:devs /var/www

# Special bits
chmod +t /tmp                  # sticky bit
chmod g+s /shared              # setgid: inherit group
chmod u+s /usr/bin/binary      # setuid: run as owner

# ACL for fine-grained access
setfacl -m u:bob:rw- report.txt
getfacl report.txt

Explanation

Linux permissions use nine bits for owner, group, and others, set with chmod in octal (755) or symbolic (u+x) form. The setuid, setgid, and sticky bits enable privileged execution, group inheritance, and deletion restrictions respectively. ACLs (setfacl) grant fine-grained access beyond the basic user/group/other model.

More Linux Snippets