Next: Finding Files
Up: File Permissions
Previous: Execute Permissions
  Contents
  Index
Expressing Permissions in Binary
The three sets of three characters are really 9 binary bits that mark 1 for yes you have the right and 0 for no, you do not. These bits are displayed in octal. If you do not know what that means then just assume that they are represented by three digits from 0 to 7, each digit representing a different set of three bits. If you wanted to give read, write, and execute rights you could represent that in binary as 111 or in octal as 7. To convert from octal assume that the first bit stands for 4, the second for 2, and the last for 1. If you can do this then you will be able to figure out what permissions to use. For a file that is read only for everyone you would use 444. For a file that was write only for everyone you would use 222. If the file was execute only for everyone the permissions would be set to 111. If you want the owner to have read, write, and execute and everyone else to have read and execute rights you would use 755. Web pages would usually be set to 644 so that the owner can read and write, but everyone else can only read them:
bash$ chmod 644 index.html
For CGI files you would have to use 755 so that the world can read and execute them:
bash$ chmod 755 results.cgi
I mentioned that there are only 9 binary bits to set permissions with, but that is not exactly correct. There are other bits that you can use to do things like setuid and setgid. With setuid the executable runs as the owner. With setgid the executable runs as the group owner. This can be accomplished by putting either a 4 (for setuid) or a 2 (for setgid) in front of the other permissions. If you wanted useradd to run as root, allowing anyone to create users you could change permissions like this:
bash# chmod 4755 /usr/sbin/useradd
If you then looked at the directory in list format, the line with useradd would look like this:
-rwsr-xr-x 1 root root 52348 Mar 9 2001 /usr/sbin/useradd
Notice the s instead of the x in the first three letters. The s stands for setuid.
Next: Finding Files
Up: File Permissions
Previous: Execute Permissions
  Contents
  Index
Joseph Colton
2002-09-24