There are 3 permissions that you can assign to a file or directory,
- Read – (R)
- Write – (W)
- EXecute – (X)
Also these 3 types of permissions can affect a file or directory by:
- Owner (u for UNIX/linux)
- Group (g for UNIX/linux)
- Everyone or Others (o for UNIX/linux)
How can I use permission on my Linux box?
Go to your terminal and type:
you should see a list like this one:
- a folder called ‘hacknplay_pictures’
- a file called ‘log_Dec14_2011_1348.txt’
drwxrwxr-x 2 mckain mckain 4096 Mar 25 18:10 hacknplay_pictures
- ‘d’ means it’s a directory (folder).
- ‘l’ means it’s a link
- ‘-’ (dash) it means it’s a file.
d >> file type (Remember ‘d’ means Directory, but it could be ‘l’ or ‘-’).
rwx >> The Owner (you (u) ) got all the rights or permissions (read, write and execute).
rwx >> The Group (g) got the same rights or permissions as the Owner (mckain).
r-x >> Everyone (Others (o)) got just ‘read’ and ‘execute’ permissions.
How to change file permissions?
- - >> Describes that it’s a file.
- rw- >> [Owner permissions] it means ‘read and write’ permissions for the the file.
- rw- >> [Group permissions] read and write permissions.
- r– >> [Other/Everyone permissions] It describes just ‘read‘ permissions.
chmod u-w frenchfries.txt
chmod u-rwx hacknplay_pictures
The command removes the read, write and execute permissions to the directory.
What about this one?
chmod guo-r hacknplay_pictures
You can use ‘combos’ too, oh yeah! when you do “guo” you are talking about the 3 different groups in the permissions file (Group (g), Owner (u) and Other (o)), so in this command we are removing the ‘read’ permissions to the 3 groups (guo).
and the last example:
chmod uo+r hacknplay_pictures
Remember about the ‘combos’ with ‘uo’ we are referring to Owner (u) and Others (o), and with the above command we apply ‘read’ permissions to the hacknplay_pictures directory.
The second way to assign permissions (The Numerical Way):
- Read (r) —— 4
- Write (w) —— 2
- Execute (x) —— 1
chmod 644 frenchfries.txt