This article explores chmod 777, a Linux command used to give ALL RIGHTS to the user, group, and others.
chmod 777 /path/to/file/or/folder
…into your Linux shell at some point.
Whenever you’re running commands on your systems (especially as root!), you should ALWAYS know what they’re up to. So what’s chmod 777 really about?
Permissions in Linux
Above is an example of running the:
command, which will list the current directory contents in the long listing format, which shows the permissions and modification dates for the files being listed.
- The first column shown is the permissions assigned to the file or directory
- The second column is the number of files or folders contained
- The third and fourth columns show the user and group who have permissions for those files, respectively
- The fifth and sixth show the size and modification date
- The final column shows the name of the file
The first, third, and fourth columns contain information relevant to permissions, which will be referenced in this article
The folders listed in the screenshot are in the linuxscrew users home directory, and all have the permission
With both the owner and group of the linuxscrew user who owns them.
drwxr-xr-x contains 4 pieces of information, 3 of them regarding permissions:
|It’s a directory||Owner can Read, Write, eXecute||Group can Read, eXecute||Others can Read, eXecute|
- The first letter shows what type of file – if it’s d it’s a directory, if it’s – it’s a regular file
- The 2nd-4th characters contain the permissions for the user
- The 5th-7th characters contain the permissions for the group
- The 8th-10th characters contain the permissions for others
The letters in each block have the following meanings:
- ‘-‘ permission denied
- ‘r’ read permission
- ‘w’ write permission
- ‘x’ execute permission
There are also some special values that the eXecute character can take:
- ‘s’ setuid bit, found in the user or group permissions, users able to execute the file will execute with the privileges of the file’s owner and/or the file’s group. It means that x is set, making the file executable
- ‘S’ Same as ‘s’ but the file is not executable
- ‘t’ Sticky bit, found in the others permissions, makes the file sticky – only the owner can rename or delete the file or files within. Group and others cannot! It also means that x is set, making the file executable
- ‘T’ Same as ‘t’ but the file is not executable
For completeness, different file types can occupy the first character space:
- ‘-‘ regular file
- ‘b’ block special file
- ‘c’ character special file
- ‘C’ high performance (“contiguous data”) file
- ‘d’ directory
- ‘D’ door (Solaris 2.5 and up)
- ‘l’ symbolic link
- ‘M’ off-line (“migrated”) file (Cray DMF)
- ‘n’ network special file (HP-UX)
- ‘p’ FIFO (named pipe)
- ‘P’ port (Solaris 10 and up)
- ‘s’ socket
- ‘?’ some other file type
What the 777 Means
To make things quicker to type when assigning permissions, numbers can be used to represent combinations of the letters shown above:
- 7 All rights
- 6 Read and write
- 5 Read and execute
- 4 Read-only
- 3 Execute and write
- 2 Write only
- 1 Execute only
- 0 No rights
So, to give ALL RIGHTS to both the user, group, and others, we’d want to assign the permission 777
The chmod Command
The chmod (Change Mode) command lets you apply permissions to files.
chmod 777 /path/to/file/or/folder
…will give the file or folders owner (user), group (users within the group), and others (everyone else on the system) full read, write and execute privileges.
chmod -R 777 /path/to/file/or/folder
This will do the same thing, recursively, and give everyone full rights on the files contained within a directory.
Now you know!