Understand rwx permissions, change them with chmod, change ownership with chown, and understand sudo.
Permissions and Users is one of the most important topics in Linux in 5 Days. This lesson builds the foundation you need before moving to more advanced concepts — take time with each example and run the code yourself.
-rwxr-xr-- 1 bo staff 1234 Apr 10 script.sh │└──┬──┘└──┬──┘└──┬──┘ │ │ │ └─── others: read only (r--) │ │ └────────── group: read+execute (r-x) │ └───────────────── owner: read+write+execute (rwx) └───────────────────── file type: - = file, d = directory
# Symbolic mode chmod +x script.sh # add execute for everyone chmod -w file.txt # remove write for everyone chmod u+x script.sh # add execute for owner only chmod go-w file.txt # remove write from group and others # Octal mode (more common in practice) chmod 755 script.sh # rwxr-xr-x (owner all, others read/exec) chmod 644 file.txt # rw-r--r-- (owner rw, others read) chmod 600 secret.key # rw------- (owner only) chmod 700 private_dir/ # rwx------ (owner only)
# Change owner chown bo file.txt chown bo:staff file.txt # owner:group chown -R bo ./mydir/ # recursive # sudo: run as root sudo apt install nginx sudo systemctl restart nginx sudo nano /etc/nginx/nginx.conf # Switch to root (avoid where possible) sudo -i # See who has sudo access cat /etc/sudoers
755 = owner can do anything, everyone else can read and traverse. 600 = owner only, no one else.Before moving on, make sure you can answer these without looking: