This article details Linux file permissions, what they look like, how to set them, and how to read the permissions as you would see them in the terminal.
File Permissions
EXAMPLE: A line from the output of ls -lah
.
-rwxr-xr-x 1 userna5 userna5 2.6K Jun 8 17:23 script.pl
In this example, -rwxrw-r-x
is the permissions of this file. The first userna5
is the file's owner, while the second userna5
is the group assigned to the file.
The First Character – Type
As we can see from the above permissions listing the very first character is -
- ‘-‘ This particular item is a file
- ‘d’ If the first character is ‘d’ that tells us that it is a directory
- ‘l’ If it shows as ‘l’ as in L, it tells us that it is a symbolic link
Characters of the File Permissions Broken Down
TYPE | USER | GROUP | WORLD |
- | rwx | r-x | r-x |
The Three Access Classes
There are three levels of access that permissions can be set for the user, group, and world.
- User – The user is the owner of the file. Every file must have an owner, which is one specific user on the machine. The owner can set specific permissions on the file as they see fit.
EXAMPLE: In the example, the user is userna5. The user’s permissions are indicated by the second, third, and fourth characters in the permissions which arerwx
in the above example. - Group – All users are part of a group. The group that the owner belongs to is granted permissions to the file as well, as set by the owner of the file.
EXAMPLE: In this example, the group only contains one user and is the same name as the owner, userna5. The group’s permissions are indicated by the fifth, sixth, and seventh characters in the permissions (r-x in the above example). - World – The world is considered anyone who is not the owner of the file or a member of the same group as the owner. In terms of web hosting, this can generally be considered the viewing public of the Internet. Like the other classes, the owner can set permissions for this as well.
EXAMPLE: The group’s permissions are indicated by the eighth, ninth, and tenth characters in the permissions (r-x in the above example).
The Three Types of Permissions
There are three types of permissions to be granted to each access class: read, write and execute.
- read – The read permission simply allows someone to view the file.
In our example, we can see that the user, group, and world have read permissions, which are indicated by an r in the class’ first permissions slot. The numerical value for read is 4. - write – The write permissions allow someone the ability to make modifications to a file.
In our example, only the user has the ability to write to the file, which is indicated by a w in the class’ second permissions slot. This is typical, as it would be a security risk to allow the group or world to write to the file. The numerical value for write is 2. - execute – The execute permission allows someone to run an executable script.
In terms of web hosting, this needs to be done for Perl and CGI scripts, which run as shell scripts and require this permission set to function properly. In our example, all users have the ability to execute the script, which is indicated by an x in the class’ third permissions slot. The numerical value for execute is 1.
What Purpose is the Numerical Value?
The numerical value is used in the command line when setting the permissions for a file or directory. Depending on the permissions you want, just add them together to find the correlating numerical value to enter in the command line. Here is what we mean:
The above example was -rwxr-xr-x. The numerical value for this is 755.
-
The user has all permissions, rwx (4+2+1=7), as it can read, write and execute.
-
The group has read and executed permissions, r-x (4+0+1=5).
-
The world has read and executed permissions, r-x (4+0+1=5).
To set this in the command line, we would use chmod 755 script.pl
Comments
0 comments
Article is closed for comments.