Posted 04.11.2004 | Updated 23.05.2006 | Contributed by Andy Mallett
CHMOD enables the setting of user permissions on files and directories. This is the main way file access is controlled under Unix.
$ls -la displays permissions on all files and directories in this 10-character format:
drwxr-xr-x name
This readout follows a strict pattern. The first character d indicates a directory.
If the first character is a - (hyphen or dash) then we are looking at a file. The following would be a file:
-rwxr-xr-x name
|
|
The other nine characters indicate permissions for three groups, in this order:
user (owner) | group | others - remember ugo!
So in the examples above, user has rwx, group has r-x and others have r-x
r stands for read permission
w stands for write permission
x stands for execute permission
Another example..
-rwxr-xrwx smb.conf
Here we have a file called smb.conf where user has read, write and execute rights; group has read and execute rights and finally others have read, write and execute rights.
The most common way of using use chmod to modify permissions is thus:
$chmod 755 name
Here we are modifying a file or directory called name. The order of the three numbers is important as they correspond to the ugo sequence..
user is 7, group is 5 and others is 5
What do the numbers mean? Well these numbers correspond to the following grid:
user group others
r w x r w x r w x
- - - - - - - - -
0 0 0 = 0 0 0 0 = 0 0 0 0 = 0
0 0 1 = 1 0 0 1 = 1 0 0 1 = 1
0 1 0 = 2 0 1 0 = 2 0 1 0 = 2
0 1 1 = 3 0 1 1 = 3 0 1 1 = 3
1 0 0 = 4 1 0 0 = 4 1 0 0 = 4
1 0 1 = 5 1 0 1 = 5 1 0 1 = 5
1 1 0 = 6 1 1 0 = 6 1 1 0 = 6
1 1 1 = 7 1 1 1 = 7 1 1 1 = 7
So for each of the three columns above, user, group and others..
a 7 would mean, read, write, execute for that user
a 4 means read only for that user
a 5 means read and execute but not write, for that user
Some of the combinations are not used. For instance 077 where group and others have full control, but the owner (user) has none. Other combinations are very commonly used, such as 755 on applications and 644 on files.
To change ownership of a file or directory, use the chown command..
$chown newowner name
i.e. $chown andym test.txt - makes andym the new owner of test.txt
More Information:
http://www.tldp.org/LDP/intro-linux/html/sect_03_04.html
|