This quick reference cheat sheet provides a brief overview of file permissions, and the operation of the chmod.
$ chmod [options] <permissions> <file>
$ chmod 755 foo.txt
$ chmod +x quickref.py
$ chmod u-x quickref.py
$ chmod u=rwx,g=rx,o= quickref.sh
$ chmod -R 755 my_directory
The chmod command stands for "change mode"
Read β β β
Write β β β
Execute β β β
Chmod Generator allows you to quickly and visually generate permissions in numerical and symbolic.
400 β r-------- β Readable by owner only
500 β r-x------ β Avoid Changing
600 β rw------- β Changeable by user
644 β rw-r--r-- β Read and change by user
660 β rw-rw---- β Changeable by user and group
700 β rwx------ β Only user has full access
755 β rwxr-xr-x β Only changeable by user
775 β rwxrwxr-x β Sharing mode for a group
777 β rwxrwxrwx β Everybody can do everything
$ ls -l
-rw-r--r-- 1 root root 3 Jun 29 15:35 a.log
drwxr-xr-x 2 root root 2 Jun 30 18:06 dir
d rwx r-x r-x
β¬ ββ¬β ββ¬β ββ¬β
β β β β
β β β ββ 4. Otherο½5 (4+0+1)
β β βββββββ 3. Groupο½5 (4+0+1)
β ββββββββββββ 2. User ο½7 (4+2+1)
ββββββββββββββββ 1. File Type | directory
--- β No Permission β 000 β 0 (0+0+0)
--x β Execute β 001 β 1 (0+0+1)
-w- β Write β 010 β 2 (0+2+0)
-wx β Execute and Write β 011 β 3 (0+2+1)
r-- β Read β 100 β 4 (4+0+0)
r-x β Read and Execute β 101 β 5 (4+0+1)
rw- β Read and Write β 110 β 6 (4+2+0)
rwx β Read, Write and Execute β 111 β 7 (4+2+1)
u β User
g β Group
o β Others
a β All, same as ugo
r β Read β 4
w β Write β 2
x β Execute β 1
- β No permission β 0
d β Directory
- β Regular file
l β Symbolic Link
+ β Add
- β Remove
= β Set
$ chmod 600 example.txt
$ chmod u=rw,g=,o= example.txt
$ chmod a+rwx,u-x,g-rwx,o-rwx example.txt
$ chmod 664 example.txt
$ chmod u=rw,g=rw,o=r example.txt
$ chmod a+rwx,u-x,g-x,o-wx example.txt
$ chmod 777 example.txt
$ chmod u=rwx,g=rwx,o=rwx example.txt
$ chmod a=rwx example.txt
Deny execute permission to everyone.
$ chmod a-x chmodExampleFile.txt
Allow read permission to everyone.
$ chmod a+r chmodExampleFile.txt
Make a file readable and writable by the group and others.
$ chmod go+rw chmodExampleFile.txt
Make a shell script executable by the user/owner.
$ chmod u+x chmodExampleScript.sh
Allow everyone to read, write, and execute the file and turn on the set group-ID.
$ chmod =rwx,g+s chmodExampleScript.sh
In order to remove read write permissions given to a file, use the following syntax:
$ chmod o-rw example.txt
For our file example.txt, we can remove read write permissions using chmod for group by running the following command:
$ chmod g-rx example.txt
To remove chmod read write permissions from the group while adding read write permission to public/others, we can use the following command:
$ chmod g-rx, o+rx example.txt
But, if you wish to remove all permissions for group and others, you can do so using the go= instead:
$ chmod go= example.txt
$ chmod +x ~/example.py
$ chmod u+x ~/example.py
$ chmod a+x ~/example.py
$ chmod 754 foo.sh
$ chmod u=rwx,g=rx,o=r foo.sh
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/id_rsa
$ chmod 600 ~/.ssh/id_rsa.pub
$ chmod 400 /path/to/access_key.pem
$ chmod -R 644 /var/www/html/
$ chmod 644 .htaccess
$ chmod 644 robots.txt
$ chmod 755 /var/www/uploads/
$ find /var/www/html -type d -exec chmod 755 {} \;
$ chmod -R 644 /your_path
$ find /path -type d -exec chmod 755 {} \;
$ find /path -type f -exec chmod 644 {} \;
See: Command Substitution