How do Unix File Permissions work?

Unix file permissions are based upon an octal code. Unix file permissions are stored in a ten character array.

The first character of the file permissions stores the file type. The standard file types are:

CharacterMeaning
-Plain file
dDirectory
cCharacter device
bBlock device
lSymbolic link
sSocket
= or pFIFO

The next nine characters are divided into three groups of three characters, each of which represents a different role on the system:

The three sets of three characters represent the permissions to the file for each role. The three permissions which may be granted to each role are:

A Unix File Permissions Example

A sample set of file permissions:

-rw-rw-r-- 1 will staff file-permissions.shtml

The file permissions for this file are:

RolePermissions
Userrw-
Grouprw-
Otherr--

This means that the user, or a member of the "web" group, can Read or Write this file. Any other user on the system can Read this file.

Unix File Permissions SUID and SGID Bits

File permissions are also used to make a program or shell script SUID (Set User ID) or SGID (Set Group ID). If a file is SUID, it will run with the privileges of the files owner, instead of the privileges of the person running the program. If a file is SGID, it will run with the privileges of the files group owner, instead of the privileges of the person running the program.

SUID and SGID programs are used to enable normal system users to accomplish tasks which would otherwise require privileged access.

The `passwd` program allows users to change their passwords. This requires the ability to write to the /etc/passwd file (and most often the shadowed password file), which unprivileged users should not normally have.

The file permissions of /usr/bin/passwd are:

-r-sr-xr-x  2 root  wheel  /usr/bin/passwd

The 's' in the space normally occupied by the first 'x' signifies that this file is SUID. No matter who executes this program, it will always run with the privileges of the user root.

Expressing Unix File Permissions in Octal

Unix file permissions are sometimes expressed in octal notation. r is equal to the value 4, w is equal to the value 2, and x is equal to the value 1.

Mathematically, rwx equals 7, because 4+2+1=7. Similarly, rw- is equal to 6 and r-x is equal to 5.

Setting Unix File Permissions

Unix file permissions are set using the `chmod` program. `chmod 644` will set a files permissions to -rw-r--r--.

Practical Unix and Internet Security Essential System Administration Unix System Administration Handbook Linux Security Cookbook
Purchase these excellent books on Unix security and administration at Amazon.com


Bookmark How do Unix File Permissions work?

Latest Blog Posts


English English GermanGerman SpanishSpanish FrenchFrench ItalianItalian PortuguesePortuguese RussianRussian DutchDutch
GreekGreek HindiHindi JapaneseJapanese KoreanKorean ChineseChinese Chinese (Simplified)Chinese (Simplified) ArabicArabic

Copyright 2009 Tech-FAQ. All rights reserved. Privacy Policy.