Mark Hobley
FILE PERMISSIONS


EXT 2 File Permissions


Permission Bits and File Types

Bit 1 2 3 4 5 6 7 8 9 10
Purpose Type User
(R)
User
(W)
User
(X)
Group
(R)
Group
(W)
Group
(X)
Other
(R)
Other
(W)
Other
(X)
Value
4 2 1 4 2 1 4 2 1

Types

(-) regular file (b) block (buffered) device file (c) character (unbuffered) device file (d) directory (l) symbolic link (s) socket (p) named pipe

SUID, SGID and Sticky Bits

Purpose SUID SGID Sticky
Value 4 2 1

SUID

A suid permission can be set against either the User(X) or Group(X) bit.

When the execute bit for the owner is set to "s", this causes the file, when run, to have system access as the owner of the file. When the execute bit for the group is set to "s", this causes the file, when run, to have system access as the group the file belongs to.

This sets the user suid bit on the file "myfile":

chmod +s myfile


This sets the group suid bit on the file "myfile2":
chmod g+s myfile2


These files appear as follows:
-rws--x--x   1 root   root   1024 Jan 1 1990 myfile
-rwx--s--x 1 root root 1024 Jan 1 1990 myfile2


Note: -rws--x--x indicates that both the user execute and user suid bit are set, -rwS--x--x indicates that the user suid bit is set, but the user execute bit is not.

The suid bit has a value of 4 in the first digit of a four digit octal representation.

SGID

If the sgid bit on a directory is set, files in that directory will be created with the group ownership of the directory, instead of the group of the user that created the file.

This sets the sgid bit on the directory "mydir":

chmod g+s mydir


This directory will appear as follows:
drwx--s---   1 mark   sgid   1024 Jan 1 1990 mydir


Note: drwx--s--- indicates that both the group execute and group sgid bit are set, drwx--S--- indicates that the group sgid bit is set, but the group execute bit is not.

The sgid bit has a value of 2 in the first digit of a four digit octal representation.

Sticky Bit

If the sticky bit (saved text attribute) on a directory is set, only the user that created a file in this directory, the owner of the directory, or root can delete that file.

To set the sticky bit on the directory "mydir":

chmod +t mydir

This directory will appear as follows:
drwxrwx--t   1 mark   sticky   1024 Jan 1 1990 mydir

Note: drwxrwx--t indicates that the others execute and the sticky bit are set, drwxrwx--T indicates that the sticky bit is set, but the other execute bit is not.
The sticky bit has a value of 1 in the first digit of a four digit octal representation.