On Linux (same goes for all POSIX systems) each file has its own permissions in relation to the system users, split between owner, group and others. Owner is the owner of the file, shown here (ls -l command output)
-rw-r--r-- 1 casey casey 3481 2011-04-02 09:49 /home/casey/.bashrc
Group is the group of the owner of the file, shown here
-rw-r--r-- 1 casey casey 3481 2011-04-02 09:49 /home/casey/.bashrc
Others are all the other users. So for each of these user groups you can set the file permissions, which are shown here
-rw-r--r-- 1 casey casey 3481 2011-04-02 09:49 /home/casey/.bashrc
So discarding first flag (-rw-r--r--) there are 3 groups of 3 flags each. First 3 flags indicate owner permissions, which are rw-, which means read/write but no execute permissions. Next 3 flags are group permissions r-- and last are other users permissions r--.
To change the permissions for a given file you MUST either be its owner or root. Use the chmod command. There are several ways to use chmod. Easier way is
- Code: Select all
chmod [u/g/o][+-][rwx] file_path
u - user, g - group, o- others
+ add permission, - remove permission
r - read, w - write, x - execute
For example chmod g-x file removes execution permissions for the file owner group.
Another more advanced use of chmod is using octal permissions, which goes like this: each of the grouped permissions are considered an octal number (3 bits) since they're flags (0 not set, 1 set). So for example rw- = 110 = 6. Grouping the 3 fields we get 3 octal digits. So for example, setting a file permissions to being all permissions for owner and only reading for the rest would go
- Code: Select all
chmod 744 file
where 744 = 111 100 100 = rwxr--r--
All this can also be done by GUI selecting the file, properties then permissions. I still prefer doing it on the terminal because IMO it's faster, and you might find yourself needing to do it through console some day.





