Script Valley
Linux & Bash for Developers
Linux Fundamentals & File SystemLesson 1.5

Linux file permissions and chmod explained

read write execute bits, user group other, octal notation, chmod symbolic mode, chown, sudo, permission denied errors

Every File Has Three Permission Sets

Run ls -l and you see something like -rwxr-xr--. The first character is the file type (- for file, d for directory). The next nine characters are three sets of three: permissions for the owner, the group, and everyone else.

Reading Permission Bits

Each set has three positions: r (read=4), w (write=2), x (execute=1). A dash means the permission is absent. rwx = 4+2+1 = 7. r-x = 4+0+1 = 5. r-- = 4+0+0 = 4.

# Make a script executable
chmod +x deploy.sh

# Set exact permissions using octal
# 755 = owner:rwx group:r-x other:r-x
chmod 755 deploy.sh

# 600 = owner:rw- only (good for private keys)
chmod 600 ~/.ssh/id_rsa

# Change ownership to another user
chown www-data:www-data /var/www/html

# Check current permissions
ls -l deploy.sh

Why Permission Denied Happens

You get Permission denied when you try to read a file without r, write without w, or execute without x. Use sudo to run a command as root — but only when necessary. Avoid running your whole application as root.