DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 5th June 2008
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Helpful companion
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Thanked 193 Times in 184 Posts
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
  #2   (View Single Post)  
Old 5th June 2008
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Thanked 112 Times in 104 Posts
Default

Thanks, I don't think I've actually ever seen it written out that way before.


I get the chmod flags in octal, I understand the logic of the binary representation readily, but for the life of me I don't think I'll ever convert octal to binary without a headache >_>


If man had been meant to count in octal, he would have been created with 10 fingers.
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote
  #3   (View Single Post)  
Old 5th June 2008
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,116
Thanked 182 Times in 149 Posts
Default

The chmod (1) man page also documents how to use symbolic notation to change the mode of a file.

For example to set the execution bit for the owner/user of the file
Code:
chmod u+x
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
  #4   (View Single Post)  
Old 5th June 2008
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Helpful companion
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Thanked 193 Times in 184 Posts
Default

Quote:
Originally Posted by TerryP
I get the chmod flags in octal, I understand the logic of the binary representation readily, but for the life of me I don't think I'll ever convert octal to binary without a headache >_>
If you can count to 7 in binary.. 0/1/10/11/100/101/110/111.. that's every possible octal value.

Last edited by BSDfan666; 5th June 2008 at 10:31 PM.
Reply With Quote
  #5   (View Single Post)  
Old 7th June 2008
chris chris is offline
Port Guard
 
Join Date: May 2008
Location: United Kingdom
Posts: 35
Thanked 6 Times in 3 Posts
Default

Thanks, this was helpful
Reply With Quote
Reply

Tags
binary, chmod, octal, permissions, unix

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Permissions error J05HYYY NetBSD Package System (pkgsrc) 1 7th October 2009 11:05 PM
Permissions for zzz / acpiconf Mantazz FreeBSD General 0 15th September 2009 10:43 PM
permissions and FTP/HTTP Yuka FreeBSD General 0 20th October 2008 10:32 PM
Designing BSD Rootkits: An Introduction to Kernel Hacking cajunman4life Book reviews 2 21st June 2008 03:27 PM


All times are GMT. The time now is 07:30 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick