
Learn how Linux permissions work, how to use chmod
, chown
, and groups to control access. Applies to Ubuntu, Debian, CentOS, and AlmaLinux.
Before starting make sure ur linux is ready.
- Ubuntu: ubuntu.com/download
- Debian: debian.org/distrib
- CentOS Stream: centos.org/download
- AlmaLinux: almalinux.org/download
- Talkecho full toturial: Click here
Understanding Linux File Permissions
Run ls -l
to see file permissions:
-rw-r--r-- 1 alex users 1234 Aug 16 10:00 notes.txt
- – → file type (
-
file,d
directory,l
link) - rw- → owner permissions (read + write)
- r– → group permissions (read only)
- r– → others permissions (read only)
Linux File Permissions Types
- r = read (4)
- w = write (2)
- x = execute (1)
Numbers combine these values (e.g., 7 = rwx
, 6 = rw-
, 5 = r-x
).
Changing Permissions with chmod
# symbolic method
chmod u+x script.sh # give execute to user
chmod g-w report.txt # remove write from group
chmod o-r secret.txt # remove read from others
# numeric method
chmod 755 script.sh # rwx for owner, r-x for group & others
chmod 644 notes.txt # rw- for owner, r-- for group & others
Changing Ownership with chown
# change file owner
sudo chown alex notes.txt
# change owner and group
sudo chown alex:staff notes.txt
# recursively change a directory
sudo chown -R alex:staff /var/www/html
Groups in Linux
Groups allow multiple users to share file access.
# add user to group
sudo usermod -aG developers alex
# list groups for user
groups alex
# create a new group
sudo groupadd editors
Special Permissions
- Setuid (s): run file with owner’s privileges.
- Setgid (s): files created in directory inherit group.
- Sticky bit (t): in shared dirs, only owner can delete their files (common in
/tmp
).
# example: sticky bit on /shared
sudo chmod +t /shared