Understand rwx permissions, change them with chmod, change ownership with chown, and understand sudo.
-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/sudoers755 = owner can do anything, everyone else can read and traverse. 600 = owner only, no one else.chmod 755 = rwxr-xr-x. chmod 644 = rw-r--r--. chmod 600 = private.sudo runs one command as root. sudo -i opens a root shell.