Aim: To explain the concept of user permissions and changing the permissions.
Every file in linux has 3 kinds of permissions Read,write and execute, these permissions are with respect to three kinds of users.
1. The owner of the file, i.e. the user who created the file.
2. The group to which the owner of the file belongs to.
3. Every one else or called as others.
To view the permissions that a file holds use the long listing format of the "ls" command. i.e. ls -l
For eg:
user@Desktop:~/folder1$ ls -l
total 12
drwxr-xr-x 2 satish satish 4096 2010-04-25 20:59 one
drwxr-xr-x 2 satish satish 4096 2010-04-25 20:59 three
drwxr-xr-x 2 satish satish 4096 2010-04-25 20:59 two
user@Desktop:~/folder1$
The first line in the long listing will is the total size of the folder.
From the second line onwards there are 17 columns. Which give the following information.
Column1:
The first field denotes what kind of file it is. A "d" indicates it is a directory . A "-" indicates it is a normal text file.
A "l" indicates it is a soft link. [ If you don't understand soft link then its ok, we will come to that later]
The remaining 9 fields of the columns one are the permissions of the file.
A "r" indicates "read" permission .
A "w" indicates write permission .
A "x" indicates execute permission.
The first set of three fileds indicate the permission of the owner of the file
The second set of three fileds indicate the permission of the group to which the owner belongs
The third set of three fields indicate the permission of the others, who are neither the owner of the file nor belong to the group of the owner.
The command to change permissions of a file is "chmod" which stands for change mode.
syntax: chmod "permissions" file
The permissions that you have we want to set can be passed in two ways.
octal numbers:
If you are not familiar with the octal numbers than skip this section. There is another way of setting the permission given in the next section.
We have three fields per user, a "1" in a field indicates that permission is eanbled a "0" indicates the permission is disabled.
Three bits in binary can maximum represent the number "7".
For eg the octal way of denoting the permissions , user having read,write execute, Group having read and write and others having only read permission would be
111110100 which when converted to octal would be 764.
so the command would be as follows.
user@Desktop:~/folder1$ chmod 764 "filename"
user@Desktop:~/folder1$
Changing File permissions using aplhabets:
The other way of setting the file permissions is using the "alphabets" "r" for read, "w" for write and "x" for execute.
A "+" signifies add permission and a "-" signifies remove permission.
To add read permission for a user use the "chmod" command as follows
user@Desktop:~/folder1/one$ chmod u+r file1
user@Desktop:~/folder1$
To add the execute permission for others we can use the "chmod" command as follows
user@Desktop:~/folder1/one$ chmod o+x file1
user@Desktop:~/folder1$
To remove write permission for the group, we can use the "chmod" command as follows
user@Desktop:~/folder1/one$ chmod g-w file1
user@Desktop:~/folder1$
To add a permission to users,group as well as others in one go, we can use the "chmod" command as follows
user@Desktop:~/folder1/one$ chmod a+x file1
user@Desktop:~/folder1$
We can also add or remove multiple permissions in one go as follows
user@Desktop:~/folder1/one$ chmod a+rw file1
user@Desktop:~/folder1$
The above command give read and write permission to every one.
Column 2:
The second column indicates the number of links to the file. We will get into the concept of links later.
Column3:Gives the owner of the file.
Column4: Gives the group to which the owner belongs to.
Column5: Gives the size of the file
Column6: Gives the last date on which it was modified.
Column7: Gives the time of modification.
Column8: Gives the file name itself.
No comments:
Post a Comment