Linux File Permissions
Using Chmod
Overview
This how to is for introducing members file permissions on Linux.
- What are Permissions
- Changing Permissions
What are Permissions
Permissions specify who can read, write or execute a file. These
permission can be found in the far left column of a long listing
(the -l switch). The first character specifies the file type ('-'
for a file, 'd' for a directory, etc), and the next nine characters
specify who has permission to do what with a file.
Permissions are broken down into three groups, each with three
permissions. The three groups are owner, group, and
other (everyone else). The owner is the person who created the
file. Group is the group the owner belongs to and other is, well everone
else!
Each group has three different modes of permission: read, write, and
execute. The permissions can be used in any combination:
-rwxrwxrwx would give everyone full access
to the file, whereas
-rwxr-xr-- would give the owner full
access, the group the owner belongs to read and execute access, and
everyone else read access.
Changing Permissions
Permissions are changed with the command chmod (change mode).
The format of the command is: chmod xyz [file]
where x,y, and z represent numbers. The numbers you specify allow you to
set the read, write and acess permissions for any group, where x is for
owner, y is for group, and z is for everyone else. Octal encoding is used
to determine each specific number, and is calculated as follows:
- Read = 4
- Write = 2
- Execute = 1
The numbers are added together for each group. So to make a file fully
accessible by it's owner, readable and execuatble by the group the owner
belongs to, and readable by everyone else (like the example above) the
numbers would be 754.
- owner: Read(4) + Write(2) + Execute(1) = 7
- group: Read(4) + Executable(1) = 5
- other: Read(4) = 4
Of course, there is an easier way for people who can't remeber the octal
numbers. The chmod command will also accept abreviations of these permissions.
For example, using: chmod +x myfile.html
will make the file myfile.html executable for all users. You can
further narrow down which groups receive permissions, these can be found
by typing man chmod.
|