Script Valley
Developer Environment Setup (WSL, Terminal, VS Code)
Linux Terminal FundamentalsLesson 2.5

How to use permissions and sudo in Linux

file permissions rwx, chmod numeric and symbolic, chown command, sudo usage, when not to use sudo, whoami, sudo vs su

File Permissions and sudo

Linux file permissions breakdown

Linux restricts who can read, write, or execute every file and directory. Understanding this prevents both access errors and accidental security holes.

Reading permissions

ls -l script.sh
# -rwxr-xr-- 1 alice dev 1024 Jun 1 script.sh

The first 10 characters: file type then three triplets of rwx for owner, group, and others.

chmod — change permissions

chmod +x script.sh
chmod 755 script.sh         # rwxr-xr-x (common for scripts)
chmod 644 config.json       # rw-r--r-- (common for files)

Numeric mode: 4=read, 2=write, 1=execute. Add them: 7=rwx, 6=rw-, 5=r-x.

sudo — run as superuser

sudo apt install curl
sudo systemctl restart nginx

Use sudo only when required — for package installs, system config changes, and service management. Do not run application code or npm install with sudo.

chown — change file owner

sudo chown alice:dev file.txt
sudo chown -R alice ~/projects