next up previous contents
Next: 1.9 Processes Up: 1.8 File and Directory Previous: 1.8.1 1.8.1 Changing ownership   Contents

1.8.2 1.8.2 Changing permissions

The permissions or mode of a file or directory can be changed with the chmod command. This can only be done by the owner of the file, or super-user (root).

You cannot change a directory to a file, or a file to directory, with the chmod command.

There are several specifications that chmod accepts. The symbolic mode which uses the letters (ugoa), (+-=), (rwxXstugo). The letters 'ugoa' control which users' access will be changed. The owner (u), other users in the group (g), others not in the group (o), or all users (a). The '+' and '-' operators determine whether the permissions are add or removed, while the '=' operator causes the permissions to be the only ones set for the file.

root@localhost # ls -l thatfile

-rw-r-r- 1 joe joe 0 Mar 30 21:46 thatfile

root@localhost # chmod u+x thatfile

-rwxr-r- 1 joe joe 0 Mar 30 21:46 thatfile
The letters 'rwxXstugo' select the new permissions for the affected users:

read (r)

write (w)

execute (x) or access for directories

execute (X) only if the file is a directory or already has execute permissions for some users

suid (s) set user or group ID on execution, in other words, execute the program as the owner of the file instead of the user that called the program

save program text (t) ``sticky bit'' ignored by Linux on files, on directories only owners of file in that directory can delete it.

user (u) permissions that the user that is owner of the file currently has

group(g) permissions that the files group has for it.

others (o) permissions that others not user or group of the file have for it.

The numeric mode is derived by adding up the bites with values of 4 (r), 2 (w), and 1 (x). Omitted digits are assumed to be leading zeros.

Difficult unless you know binary arithmetic. Starting from left to right, each mode is represented as follows.

4000
is u+s
2000
is g+s
1000
is +t,
400
is r for user
200
is w for user
100
is x for user
40
is r for group
20
is w for group
10
is x for group
4
is r for other
2
is w for other
1
is x for other
So by adding up these number we can set the mode for a file, with a numerical value. Here's a simple example.

root@localhost # ls -l thisfile

-rw-rw-r- 1 joe joe 29 Mar 26 19:23 thisfile

root@localhost # chmod 666 thisfile

-rw-rw-rw- 1 sam sam 29 Mar 26 19:23 thisfile
The octal representations may seem difficult at first. Once you understand the octal representations, you may find them the easiest to use. Here are some of the common one:

644
is -rw-r-r- the owner can read and write, everyone else can read only.
755
is -rwxr-xr-x the owner card read, write and execute, everybody else can read or execute it. For a directory this is equivlent to
644
 
711
is -rwx-x-x the owner can read, write and execute, everyone else can only execute it.
444
is -r-r-r- this is read only permission for everyone.
There is other information contained in the 10 characters at the beginning of a listing about special files for devices, sockets, symbols, links, etc.. However since this is primarily a text for beginners, it will not be covered here.


next up previous contents
Next: 1.9 Processes Up: 1.8 File and Directory Previous: 1.8.1 1.8.1 Changing ownership   Contents