Within a directory, you can find out the file access rights by typing
ls -ls
The file access permissions is a combination of letters and hyphens. The letters and hyphens will make up 10 total symbols. The letters are d, r, w, x and occasionally s or S.
1 2 3 4 5 6 7 8 9 |
r - read w - write x- execute d - indicates a directory "-" - indicates a file |
Either d or “-” will be present at the beginning if it is a folder or file respectively.
The 9 letters from the symbols indicate the permissions or the access rights and are taken as a group of three.
The left most group of 3 gives the file permissions for the user that owns the file (or directory). The right most group gives the permissions for all others. The middle three columns indicates the permission given to the group to which the user account belongs.
The letters of the symbol will carry different meanings depending if they are simple file or directory.
Files
1 2 3 4 |
r (or -) - indicates read permission or otherwise) w (or -) indicates write permission (or otherwise) x ( or -) indicates the exceute permission (or otherwise) |
Folders
1 2 3 4 5 |
r - allow users to list files in the directory w - allow users to delete files or move files into the directory x - read files in the directory assuming you have the read right on the individual files. |
For example
1
|
-rw-------
|
The above permission signifies a file that only the owner can read and write. No one else is allowed to read or write or execute it.
Changing access rights
Chmod refers to changing file mode. Only the owner of a file can use chmod to update file permissions. The following are the chmod symbols
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
u -user g -group o -other a - all (everything including u, g, o) r - read w -write (and delete) x -execute ( and acess directory) + - add permissions "-" - take permission away |
For example, the below command will add a read write permission to the file test.txt for group and others.
1
|
chmod go +rw test.txt
|
The below command will take away the read write permission for the file testing.txt for group and others.
1
|
chmod go -rw testing.txt
|
if we want to assign read, write permissions to the test file all instead, we can assign it using the command below
1
|
chmod a+rw test
|
Permissions as integers
The following integers represent the permissions applicable to files and directories.
1 2 3 4 5 6 7 |
1 - excecute 2 - write 4 - read 0 - clear permission |
let’s take this numeric permission as an example
A permission 655 will indicate the following
6 = 4+2 – Indicating read and write
5 = 4 +1 – Indicating read and execute
We need to take the position of the numbers into account, so 655 represents ugo as each digit represents the permission for one of u, g and o. In the above example, the user has the read and write permissions, the group has the read and execute permissions and others also have the read and execute permissions.