TutsFx logo

Linux File Permissions Explained

Changing Permissions with chmod

2 min read Last updated 44 minutes ago

chmodchange mode — is how you set permissions. It has two syntaxes: symbolic and octal.

Symbolic mode

You target a group and add (+), remove (-) or set (=) a permission:

bash
chmod u+x script.sh     # owner (u) gets execute
chmod g-w notes.txt     # group (g) loses write
chmod o=r notes.txt     # others (o) are set to read-only
chmod a+r notes.txt     # everyone (a = all) gets read
chmod u+x,g-w notes.txt # combine with a comma
Reference Group
u owner (user)
g group
o others
a all three

Octal mode

Each permission has a number: read 4, write 2, execute 1. Add them up per group:

Code
rwx = 7    rw- = 6    r-x = 5    r-- = 4
bash
chmod 755 script.sh     # rwxr-xr-x — common for executables
chmod 644 notes.txt     # rw-r--r-- — common for files
chmod 600 secret.txt    # rw------- — private to the owner
chmod 700 ~/.ssh        # rwx------ — private directory

How to remember

Remember 7 = rwx. Then subtract what you don't want: 755 is "rwx for owner, r-x for everyone else".

The classic examples

Mode Result Typical use
644 -rw-r--r-- Web files, documents
755 -rwxr-xr-x Executables, scripts, directories
700 -rwx------ Private scripts, .ssh
600 -rw------- Secrets, private data
×

Why not `chmod 777`?

777 gives read, write and execute to everyone — including write access. It breaks security and is almost never the right answer. Prefer the most restrictive mode that still works.

Try it

  1. touch prog.sh then chmod +x prog.sh && ls -l prog.sh
  2. chmod 644 prog.sh — see the x disappear
  3. Create a directory chmod 700 private and verify with ls -ld
Share:

We value your privacy

We use cookies to enhance your browsing experience, serve personalized ads, and analyze traffic. By clicking "Accept", you consent to our use of cookies. Read our Privacy Policy to learn more.