UnixDroid

Permissions · Linux command

chmod command in Linux

What does chmod do?

chmod changes who can read (r=4), write (w=2) and execute (x=1) a file, for the owner, the group and everyone else. chmod 755 = rwxr-xr-x.

chmod [mode] file…

Most useful options

OptionWhat it does
+xadd execute permission
u / g / o / auser, group, others, all
755rwx for owner, r-x for others (scripts, folders)
644rw for owner, r for others (normal files)
600only the owner can read and write (private keys)
-Rapply to a folder and everything inside

chmod examples

$ chmod +x script.sh Try it ›

make a script runnable

$ chmod 600 ~/.ssh/id_rsa Try it ›

protect a private key

$ chmod -R 755 public/ Try it ›

set a whole folder

$ chmod o-r secret.txt Try it ›

remove read access for others

In security work

chmod 777 is almost always a mistake: anyone can change the file. World-writable scripts run by root are a classic privilege escalation.

Questions about chmod

What does chmod 755 mean?

Owner: read+write+execute (7). Group and others: read+execute (5).

What does chmod +x do?

It adds execute permission so the file can be run as a program.