Changing File and Directory Permissions

Users can modify the permissions on files or directories they own by using the chmod command. Regular users cannot modify the permissions of files or directories that they do not own. Members of the sysadmin group, however, can use the vchmod super command to modify the permissions on files and directories that are owned by other users, except for those owned by the user root. The root user, also known as the superuser, can change the permissions on any file using the chmod command.

Whether using the chmod or the vchmod command, you can set permissions explicitly using the permissions number system, or by assigning individual permissions based on the user type. Examples of each method are given below.

Example 1: Setting permissions via the permission numbering system

Suppose you want exclusive read, write, and execute permissions to a file called 'all.mine,' which you own. According to the numbering system, the corresponding number would be 700. To set these permissions, use the following command:

> chmod 700 all.mine

You can verify the permissions by issuing the ll command. The resulting output displays the following permissions on the all.mine file:

-rwx------

Example 2: Giving yourself permission to execute a file that you own:

Each type of user can be represented by one of the following values:

u  - The user who owns the file (usually you)

g  - Members of the group to which the owner belongs   

o  - Other users

a  - All users (includes u, g, o)

Using the “+” symbol indicates the adding of a permission, and using “-” indicates the removal of a permission.

So, to give the owner permission to execute a file, use the following syntax:

chmod u+x file1

This gives you execute permission for the file "file1".

Example 3: Giving members of the file’s group permission to write to the file:

chmod g+w file2

This gives the group permission to write to the file "file2".

Example 4: Giving read permission to all users for a particular type of file:

(The a includes "all" groups: u, g, o)

chmod a+r *.pub

This gives all users permission to read files with the ".pub" extension.

Example 5: Changing permissions on a file you don't own:

To change the permissions on a file you don't own, use the vchmod super command (Remember, only users who are members of the sysadmin group can use the vchmod command):

vchmod o-x members.only

This removes execute permissions for other users on the file "members.only".

For More Information:

For more information on file permissions and how to set them, please refer to the chmod man page by entering the following command at the command prompt:

> man chmod