Who's Online

We have 1 guest online
File Permission in Linux PDF Print E-mail
Written by Deepak K.C.   
Monday, 22 June 2009 06:30

What is file permission?

File permission is the privilege that a user gets to access the file depending on the need and the level of the user.Access to the file or group of files can be controlled. There are 3 types of access:
  • Read
  • Write
  • Execute

Depending on the requirements and the level of user we set up access to certain files. Each file belongs to a specific user and group. We can set permissions so that the owner or a certain group or user can modify, certain group can only read while the rest cannot access.

Why do we need to setup file permission?

You are likely to come across the problem that sometimes you yourself can't access some files on your  own linux system. Its due to the mis­-configured file access permission. My experience: I have waisted almost more than 1 hr after setting up the apache server. I was unable to write(modify ) any file from the /var/www directory. File permission sometimes can be frustrating even though its crucial for a secure system.File permissions help to keep our important files safe from others as well as from our own mistakes.

What is file owner ship?

Every file or directory on your linux system is owned by a specific user and group.  File permissions are defined separately for different users, groups and others.
  • User: The username of the person who owns the file. By default, the user who creates the file will become its owner
  • Group: The usergroup that owns the file. All users who belong into the group that owns the file will have the same access permissions to the file. This is useful if, for example, you have a project that  requires a bunch of different users to be able to access certain files, while others can't. In that case, you'll add all the users into the same group, make sure the required files are owned by that group, and set the file's group permissions accordingly.
  • Other: A user who isn't the owner of the file and doesn't belong in the same group the file does are termed as others. Others can also be termed as the rest of the world. We have to be very careful while assigning permissions to others.
Understanding file permissions

There are three types of access permissions on Linux: read, write, and execute. These permissions are  defined separately for the file's owner, group and all other users.
  • Read permission (R): On a regular file, the read permission bit means the file can be opened and read. On a directory, the read permission means you can list the contents of the directory.
  • Write permission (W): On a regular file, this means you can modify the file, write new data to the file. In the case of a directory, the write permission means you can add, remove, and rename files in the directory. Hence a file with a write permission bit can allow you to write on it (modify it) but unless you don't have the write permission in the directory you are not allowed to rename or delete it.
  • Execute permission (X) : On a regular file, execute permission means you can execute the file as a program or a shell script. On a directory,this permission allows you to access files in the directory and enter it with cd command but remember unless you have the read permission for that directory you are not allowed to list the contents of that directory.
Types of permissions

File permission is the privilege that a user gets to access the file depending on the need and the level of the user.Access to the file or group of files can be controlled. There are 3 types of access:

  • Read
  • Write
  • Execute
Depending on the requirements and the level of user we set up access to certain files. Each file belongs to a specific user and group. We can set permissions so that the owner or a certain group or user can modify, certain group can only read while the rest cannot access.

Why do we need to setup file permission?

You are likely to come across the problem that sometimes you yourself can't access some files on your  own linux system. Its due to the mis­-configured file access permission. My experience: I have waisted almost more than 1 hr after setting up the apache server. I was unable to write(modify ) any file from the /var/www directory. File permission sometimes can be frustrating even though its crucial for a secure system.File permissions help to keep our important files safe from others as well as from our own mistakes.

What is file owner ship?

Every file or directory on your linux system is owned by a specific user and group.  File permissions are defined separately for different users, groups and others.
  • User: The username of the person who owns the file. By default, the user who creates the file will become its owner
  • Group: The usergroup that owns the file. All users who belong into the group that owns the file will have the same access permissions to the file. This is useful if, for example, you have a project that  requires a bunch of different users to be able to access certain files, while others can't. In that case, you'll add all the users into the same group, make sure the required files are owned by that group, and set the file's group permissions accordingly.
  • Other: A user who isn't the owner of the file and doesn't belong in the same group the file does are termed as others. Others can also be termed as the rest of the world. We have to be very careful while assigning permissions to others.

Explanation of  file permissions

There are three types of access permissions on Linux: read, write, and execute. These permissions are  defined separately for the file's owner, group and all other users.

  • Read permission (R): On a regular file, the read permission bit means the file can be opened and read. On a directory, the read permission means you can list the contents of the directory.
  • Write permission (W): On a regular file, this means you can modify the file, write new data to the file. In the case of a directory, the write permission means you can add, remove, and rename files in the directory. Hence a file with a write permission bit can allow you to write on it (modify it) but unless you don't have the write permission in the directory you are not allowed to rename or delete it.
  • Execute permission (X) : On a regular file, execute permission means you can execute the file as a program or a shell script. On a directory,this permission allows you to access files in the directory and enter it with cd command but remember unless you have the read permission for that directory you are not allowed to list the contents of that directory.


file permission in linux


In this diagram :

Character 1 : defines the type of file,directory or link. - for file, d for directory , 1 for link

Character 2-4 : defines the permission for user

Character 5-7: define the permission for group 

Character 8-10: defines the permission for others

 Lets look at some examples to be more clear.

When you type ls -l in terminal you will get the list of files as below: 

The first file in the picture menu.php begins with - which meanes its a file. The first 3 letters rwx means the owner of this files has all three permissions to read,write and execute, the next 3 means the group has also same rwx permission while the last 3 r-x means the rest of the people have only  read and exectue access.

Similarly in the image you can see 2009-Jan-Courses which begins with d representing it to be a directory. The first 3 letters rwx means the owner has all 3 permissions , same is with the group while rest of the people dont have any access which means they will not be able to do anything with that directory.

You can notice deep deep and root plugdev which means the first one deep is user and another deep is group. Same with root,its user and the plugdev is group.

Last Updated on Wednesday, 24 June 2009 11:27
Read more...
 
« StartPrev12NextEnd »

Page 2 of 2