![]() |
|||||||||||||||||||||||||||||
Linux is basically a multi-user system. But nowadays there has been
an increase in the usage of Linux as an OS for single user home computers
as well. But since it was originally meant to be a multi-user
OS, a lot of things that would be necessary in a multi-user system
are built into the Linux core. One such thing is file / directory
permissions.
The first character 'f' indicates that ' viewResume ' is a file. In case it was the name of a directory there would have been a 'd' instead of a 'f' The next part rwxr-xr-x (a total of 9 characters) should be spilt into 3 parts each consisting of 3 consecutive letters Part 1 (User) : rwx Part 2 (Group) : r-x Part 3 (World) : r-x The meaning of these 3 characters which form this 9 character sequence is shown in the table below. Description of r,w,x for Files r Read permissions for the file (whether the contents of the file can be read or not) w Write permissions for the file (whether a file can be modified or not) x Execute permissions (whether a file is an executable/script or not) In Part 1 r,w and x, all the 3 permissions exist. This means that the the concerned file, ' viewResume ' can be read, written to as well as executed. Thus in case you want to just read the contents of that file you could do so. In case you want to modify the file that too would be allowed. Assuming that ' viewResume ' is some kind of a script it also has execute permissions assigned to it. So you could execute this program from the shell prompt as well. Some of you'll who are really smart must have already started thinking about how you could protect your data from others (in a multi-user system) when you have provided r,w and x permissions to the file. That is exactly why there is a 9 character sequence present instead of just 3 characters. Part 1 decides the permissions for the User (the owner of the file) Part 2 decides the permissions for other users who belong to the same Group as the file Part 3 decides the permissions for Others (rest of the world) who might access your folder As the owner any file you create would be having the r and w permissions present. In case its a script you should also add the execute permission. This is explained in a later section of this article. In case you are a part of a project involving other users, you should ask the administrator to create a separate group and include all the project members in that group. Then you could create all your programs as a part of that group and use the group permissions so that only those members belonging to your project group can read, modify your files that concern to that project. For others (rest of the world) it is always best to leave the default permissions which would be generally r and x. Never ever give w permissions to all, else anyone would be able to modify your files. The rest of the fields don't have anything to with file permissions as such. So they shall not be dealt with in this article. Now lets consider the 3rd line in the ' ls ' output.
This shows the permissions for a file aptly named ' privatedata.txt
'. The name itself suggests that this is some important file that only
the owner of the file should be allowed to read, write or execute. Thus
no one else (group or others) should be allowed to even view the contents
of this file. Thus you can see that
the permissions for the file are rwx------ Dividing it into 3 parts you would get ' rwx ' and ' --- ' and ' --- ' The - (hyphen) indicates that the particular property is not existing for that file or directory. Thus in this case the 2nd and 3rd Part only consist of hyphens thus indicating that neither the Group members nor Others would be allowed to either read, write or execute this file. You on the other hand have all these 3 properties set so that you are free to do anything with the file. Now consider the 1st line in the ' ls ' output
Note that the first
character on the line is a ' d ' which indicates that ' tutorials '
is the name of a directory and not a file.
Important : The permissions for directories take on a slightly different meaning than those for files. This is explained in some detail.
In our example the ' tutorials ' directory has r and x permissions set
for group and world. So basically all the users could view the files
that are present within that directory. Since the w permission is missing
for group and world, they cannot modify add or delete any of the files
within the tutorials directory (unless there is
a situation as described in the Note below). You on the other hand as usual are allowed to do as you wish. Doesn't Linux make you feel powerful !! Now for some technical language. Though I have been calling these r,w and x as permissions, you would generally call them as bits. So don't look surprised when a Group members asks you to set the read bit for a directory. It basically means, set the read permissions for that directory. Important : As beginners until you are completely familiar with file permissions, remember one important rule. Never give a directory lesser privileges and the files within that directory more privileges. I mean in case you do not set the x bit for a directory and set the w bit for the files within that directory. Though you may expect that since the directory doesn't have the x bit set, users cannot enter the directory and so they wont be able to modify your files. Actually the meaning of the x bit for directories is not so simple to understand. Setting permissions as above would allow anyone to delete all your files in that directory. So always give the equal or lesser privileges to the files within a directory as that to the directory itself. If you don't want the users to have write permissions to your files, remember not to set the w permissions for the files rather than trying to restrict write access using the directory permissions |
|||||||||||||||||||||||||||||
|
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |