How to use chmod command?

chmod command is used to change file or directory permissions in linux. To understand permissions you need to understand following diagram first:

Every file type in linux have following three types of permissions:

  • user (u)
  • group (g)
  • other (o)

chmod command operation related abbreviations:

abbreviation meaning
= override
+ add permissions top of existing permissions
- remove permissions top of existing permissions

chmod command abbreviations:

abbreviation meaning
u stands for user or owner of the file or directory
g stands for group which means group for given file or directory
o stands for others meaning users outside of current file or directory group
a stands for all meaning all of above

chmod command permissions table:

code number description
- 0 no permissions
r 4 read permission
w 2 write permission
x 1 execute permission

chmod command numeric code table:

code rwx description
0 000 No permissions
1 001 Execute permission only
2 010 Write permission only
3 011 Write and execute permissions only
4 100 Read only permission
5 101 Read and execute permissions only
6 110 Read and write permissions only
7 111 Read, write and execute permissions i.e. all permissions

What is chmod 777 permission?

Looking at numeric table code you can tell that 7 digit refers to Read, Write and Execute permissions. Now, 777 permissions meaning:

  • user (u) has read, write and execute permissions
  • group (g) has read, write and execute permissions
  • other (o) has read, write and execute permissions

Setting 777 permissions to a file or directory means that it will be readable, writable and executable by all users and it can create a huge security risk.

What is chmod 755 permission?

Looking at numeric table code you can tell that 7 digit refers to Read, Write and Execute permissions. Number 5 refers to Read and Execute permissions only.

Therefore 755 permission would be:

  • user (u) has read, write and execute permissions
  • group (g) has read and execute permissions
  • other (o) has read and execute permissions