View Single Post
  #1   (View Single Post)  
Old 5th June 2008
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Banned
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Red face Semi-brief introduction to file permissions,

Often you may see someone setting permissions using octal values, this may be confusing at first, but I'll try to help you out.

First, let's say someone sets the permission 666 on a file, you may have a chill run up your spine if you're religious, but it's honestly a very liberal number..

Octal, or base 8, has 8 possible values.. 0 through 7.
Binary, or base 2, has 2 possible values.. 0 and 1.

Binary is important in computing because it represents 2 universal states, ying and yang, right and wrong.. on and off.

1 is the equivalent of true.
0 is the equivalent of false.

So, 6 octal is 110 binary..

The first 2 binary digits of 6(110) represent the read and write permissions of the file, the last digit represents execute.

So, When you see "666", the first digit represents the owners permissions, the second digit represents the group permissions, the last digit represents "everyones" permissions.

In this case, everyone can read and write.. but nobody can execute the file.

Here is a basic reference:
  • 0 octal or 000 binary, no permissions.
  • 1 octal or 001 binary, execute only.
  • 2 octal or 010 binary, write only
  • 3 octal or 011 binary, write and execute
  • 4 octal or 100 binary, read only
  • 5 octal or 101 binary, read and execute
  • 6 octal or 110 binary, read and write
  • 7 octal or 111 binary, read/write and execute
Read chmod(1) for a more thorough introduction..

I should note, occasionally you may see permissions set as 4 digit octals..

For example:
$ chmod 0666 public_doc.txt
  • 0666(The same as 666)
  • 1666(sticky(8) bit)
  • 2666(setuid(2) bit)
  • 4666(setgid(2) bit)
  • 6666(setuid+setgid bits)
  • 7666(setuid+setgid+sticky bits)
This high order octal value represents some additional functionality on modern Unix systems, some are scary and are often abused..

I hope I helped somebody out, take care, feel free to post if you have questions.

Last edited by BSDfan666; 5th June 2008 at 01:03 AM.
Reply With Quote