System Administration Guide

Changing File Permissions

The chmod command enables you to change the permissions on a file. You must be superuser or the owner of a file or directory to change its permissions.

You can use the chmod command to set permissions in either of two modes:

Table 51-5 lists the octal values for setting file permissions in absolute mode.

Table 51-5 Setting File Permissions in Absolute Mode

Octal Value 

File Permissions Set 

Permissions Description 

0

---

No permissions 

1

--x

Execute permission only 

2

-w-

Write permission only 

3

-wx

Write and execute permissions 

4

r--

Read permission only 

5

r-x

Read and execute permissions 

6

rw-

Read and write permissions 

7

rwx

Read, write, and execute permissions 

Table 51-6 lists the symbols for setting file permissions in symbolic mode. Symbols can specify whose permissions are to be set or changed, the operation to be performed, or the permissions being assigned or changed.

Table 51-6 Setting File Permissions in Symbolic Mode

Symbol 

Function 

Description 

u

Who 

User (owner) 

g

Who 

Group 

o

Who 

Others 

a

Who 

All 

=

Operation 

Assign 

+

Operation 

Add 

-

Operation 

Remove 

r

Permission 

Read 

w

Permission 

Write 

x

Permission 

Execute 

l

Permission 

Mandatory locking, setgid bit is on, group execution bit is off

s

Permission 

setuid or setgid bit is on

S

Permission 

suid bit is on, user execution bit is off

t

Permission 

Sticky bit is on, execution bit for others is on 

T

Permission 

Sticky bit is on, execution bit for others is off 

The who operator permission designations in the function column specifies the symbols that change the permissions on the file or directory.

who

Specifies whose permissions are changed. 

operator

Specifies the operation to perform. 

permissions

Specifies what permissions are changed. 

How to Change Permissions in Absolute Mode

  1. If you are not the owner of the file or directory, become superuser.

    Only the current owner or superuser can use the chmod command to change file permissions on a file or directory.

  2. Change permissions in absolute mode by using the chmod command.


    $ chmod nnn  filename
    

    nnn

    Specifies the octal values that change permissions on the file or directory. See Table 51-5 for the list of valid octal values.

    filename

    File or directory. 

  3. Verify the permissions of the file have changed.


    $ ls -l filename
    

Example--Changing Permissions in Absolute Mode

The following example sets rwxr-xr-x permissions on myfile.


$ chmod 755 myfile
$ ls -l myfile
-rwxr-xr-x   1 kryten   staff   6144 May 24 10:49 myfile

How to Change Permissions in Symbolic Mode

  1. If you are not the owner of the file or directory, become superuser.

    Only the current owner or superuser can use the chmod command to change file permissions on a file or directory.

  2. Change permissions in symbolic mode by using the chmod command.


    $ chmod who operator permission filename
    

    who operator permission

    who specifies whose permissions are changed, operator specifies the operation to perform, and permission specifies what permissions are changed.

    See Table 51-6 for the list of valid symbols.

    filename

    Is the file or directory. 

  3. Verify the permissions of the file have changed.


    $ ls -l filename
    

Examples--Changing Permissions in Symbolic Mode

The following example takes away read permission from others.


$ chmod o-r filea

The following example adds read and execute permissions for user, group, and others.


$ chmod a+rx fileb

The following example assigns read, write, and execute permissions to group.


$ chmod g=rwx filec