Linux chmod Command
The chmod command sets the permissions of files or directories.
chmod <options> <permissions> <file name>
sudo chmod -R 755 /var/www/my_website
There are two ways to represent permissions
- Octal numbers (the digits 0, 1, 2, 4, 5, and 7)
- Symbols (alphanumeric characters)
Octal numbers
Octal permissions notation uses a pattern of three single-digit numbers to define all permissions. The single digit numbers 0
, 1
, 2
, 4
, 5
, and 7
used are. 3
and 6
are not used.
0
stands for “no permission.”
1
stands for “execute”.
2
stands for “write”.
4
stands for “read”.
5
stands for “read and execute” and is the combination of permissions 1
+4
.
7
stands for “read, write, and execute” and is the combination of permissions 1
+2
+4
.
Symbols
u
stands for user.
g
stands for group.
o
stands for others.
a
stands for all.
A combination of the letters ugoa
controls which users’ access to the file will be changed: the user who owns it u
, other users in the file’s group g
, other users not in the file’s group o
, or all users a
. If none of these are given, the effect is as if a
were given, but bits that are set in the umask are not affected.
That means that chmod u+x somefile
will grant only the owner of that file execution permissions whereas chmod +x somefile
is the same as chmod a+x somefile
.
The format of a symbolic mode is [ugoa...][[+-=][rwxXstugo...]...][,...]
. Multiple symbolic operations can be given, separated by commas.