Setting permissions in files and folders in Linux

Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.

Setting permissions in files and folders in Linux

Rating:

Setting permissions in files and folders in Linux

Types of permissions

Linux has three types of permissions that can be assigned to users or groups. These permissions have been described in the table below:

Types of PermissionsDescription
ReadThe Read permission, represented by "r", allows users or groups to read the files or folders for which this permission has been granted.
WriteThe Write permission, represented by "w", allows users or groups to make modifications in the files or folders for which this permission has been granted. This permission also allows deleting files or folders.
ExecuteThe Execute permission, represented by "x", allows users or groups to execute or search the files or folders for which this permission has been granted.


The permissions on a file or folder are represented in the following format:

rwxrwxrwx

Basically, this is a group of three permissions. The first three characters are for the owner (user) of a file or folder, the next three characters are for a group, and the last three characters are for others.

Setting Permissions on files and folders

Linux uses numbers to set permissions on files and folders. The numbers are from 0 to 7. Each number corresponds to a setting of Read, Write, and Execute permissions.

Following is the number chart of permissions:

NumbersRead (r)Write (w)Execute (x)
0 No No No
1 No No Yes
2 No Yes No
3 No Yes Yes
4 Yes No No
5 Yes No Yes
6 Yes Yes No
7 Yes Yes Yes


To set the permissions, you use a set of three numbers. The first number belongs to the owner, the second number belongs to a group, and the third to others.


Example

In order to grant Read, Write, and Execute permissions to the owner, to a group, and to others, you will have to set permissions as 777. The first number 7 will provide r, w, x permissions to the owner. The second and third 7s will provide the same permissions to the group and to others, respectively.

Similarly, if you do not want to provide w, r, and x permissions to others, you will have to set the permissions as 770.

Scenario

Problem: You have created a folder named Crack. You want a user named David to become the owner of this folder and have full permissions on it. You also want a group named JAdmin to have Read and Execute permissions. You want to prevent other users from accessing the Crack folder. What steps will you take?

Solution: First of all, you will have to make David the owner of the folder and permit the JAdmin group to access the folder. This can be done by executing the following command:

CHOWN david.jadmin crack

By listing the folder, you will get the following result:

drwxr-xr-x David JAdmin Crack

You can see that David already has r, w, and x permissions, whereas the JAdmin group and others have only r and x permissions. Now, as you do not want to give others any access to the Crack folder, you will have to execute the following command:

CHMOD 750 crack

This will meet all the necessary requirements of the scenario. Listing the folder will provide you the following result:

drwxr-x--- David JAdmin Crack


Rating:



Other articles

Click here to Article home

 
uCertify.com | Our Company | Articles | Privacy | Security | Contact Us | News and Press Release | uCertify India
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD Cisco Certification: CCNA, CCENT, A+, Network+, Security+
Oracle Certification: OCP 9i, OCP 10g, OCA 9i, OCA 10g CIW foundation    EC-212-32    CISSP    Photoshop ACE    Adobe Flash ACE
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.