Page 1 of 2
 1  2  >
Closed Thread
   
 Coming To Grips With Chmod And Chown. 
 
 
  #1 (permalink)  
Old 01-05-2005, 08:07 AM
Regular

Group: Forum Leaders
Location: Sydney


Quote:
purana:~/Desktop/temp michaelf$ ls -l
total 0
-rw-r--r--* 1 michaelf* michaelf* 0* 1 May 08:14 file
Before using chown or chmod I will explain the output above and what part of the directory listing of this file is affected
by the use of either command.

First chown. chown allows us to change the owner and group of a file. As you see above in the example I have our current
owner and group is michaelf:michaelf (or expressed as michaelf.michaelf on some other UNIX variants) To change the owner and/or group you can use
the chown command.

Load terminal.

Quote:
Example;

purana:~/Desktop/temp michaelf$ sudo chown michaelf:nobody file
purana:~/Desktop/temp michaelf$ ls -l
total 0
-rw-r--r--* 1 michaelf* nobody* 0* 1 May 08:14 file
As you can see the group has been changed to nobody, owner still remains as michaelf.
Quote:
Example;

purana:~/Desktop/temp michaelf$ sudo chown nobody:nobody file
purana:~/Desktop/temp michaelf$ ls -l
total 0
-rw-r--r--* 1 nobody* nobody* 0* 1 May 08:14 file
If we wanted to apply a change to say a directory and all the files/folders below it, then you'd use the following additionial switches
Quote:

Example;

purana:~/Desktop/temp michaelf$ ls -l
total 0
drwxr-xr-x* 6 michaelf* michaelf* 204* 1 May 08:36 dir
-rw-r--r--* 1 nobody* * nobody* * * 0* 1 May 08:14 file
purana:~/Desktop/temp michaelf$ ls -l dir
total 0
-rw-r--r--* 1 michaelf* michaelf* 0* 1 May 08:36 file1
-rw-r--r--* 1 michaelf* michaelf* 0* 1 May 08:36 file2
-rw-r--r--* 1 michaelf* michaelf* 0* 1 May 08:36 file3
-rw-r--r--* 1 michaelf* michaelf* 0* 1 May 08:36 file4
purana:~/Desktop/temp michaelf$ sudo chown -R nobody:nobody dir
purana:~/Desktop/temp michaelf$ ls -l dir
total 0
-rw-r--r--* 1 nobody* nobody* 0* 1 May 08:36 file1
-rw-r--r--* 1 nobody* nobody* 0* 1 May 08:36 file2
-rw-r--r--* 1 nobody* nobody* 0* 1 May 08:36 file3
-rw-r--r--* 1 nobody* nobody* 0* 1 May 08:36 file4
Now we have owner nobody and group as nobody. The chown command will take many swithes, so if you want to dig deeper be sure
to consult the man page for the command. This can be done by using man (man chown).

That concludes chown, now lets discuss chmod.

Lets start with the following;
Quote:

purana:~/Desktop/temp michaelf$ ls -l
total 0
drwxr-xr-x* 6 nobody* nobody* 204* 1 May 08:36 dir
-rw-r--r--* 1 nobody* nobody* * 0* 1 May 08:14 file
The bits in front of the files/directories as shown above can be changed using chmod, but first I will break down the bits
and tell you an easy way to remember values etc.

(-) --- --- ---
The first bit as shown above is reserved for showning special bits, in the example above it shows
us a dir contains this field as a d, where as a file it is blank. This is all we really need to concentrate on at the moment.

- (---) --- ---
The next 3 bits relate to the owners permission to this file and/or directorey (contains any combination of rwx)

- --- (---) ---
The next 3 bits relate to the groups permission to this file and/or directory (contains any combination of rwx)

- --- --- (---)
The next 3 bits relate to the group other and what permission other has to this file and/or directory (contains any combination of rwx)

To change the various permissions for each of the bits, its expressed using a 3 digit number. To remember the various combinations for
setting these permissions, we can use the following rules.

(rwx) (rwx) (rwx)
(421) (421) (421)

For a file, r= read, w= write and x= execute (can run/launch a file)
For a dir, r= read, w= write and x= execute (can list (ls) a dir and see the files inside it)

Just add up the numbers below the bits to get your final permissions.

ie. Say I wanted to give the permissions of rw-rw-rw, then I would add up the numbers accordingly.
(4+2=6) (4+2=6) (4+2=6), which then means my 666 would be the 3 digit number passed to my file.
Quote:

Example;

purana:~/Desktop/temp michaelf$ ls -l
total 0
drwxr-xr-x* 6 nobody* nobody* 204* 1 May 08:36 dir
-rw-r--r--* 1 nobody* nobody* * 0* 1 May 08:14 file

purana:~/Desktop/temp michaelf$ sudo chmod 666 file
purana:~/Desktop/temp michaelf$ ls -l
total 0
drwxr-xr-x* 6 nobody* nobody* 204* 1 May 08:36 dir
-rw-rw-rw-* 1 nobody* nobody* * 0* 1 May 08:14 file
And as you can see our file now has the rw-rw-rw permissions.

Very easy isn't it. I won't do another example, I think people can go off and explore it for themselves.

And if you wanted to do a whole dir of files, then you could use the -R switch as shown previously.

This concludes my quick tutorial. I hope people find it of benefit.
__________________
MacBook 2.4Ghz C2D Superdrive w/ 4Gb ram, 160Gb HDD (White)
iMac 20" 2.16Ghz C2D w/ 3Gb ram, 256Mb video ram (White)
iPhone 3G 8Gb
1Tb Time Capsule
purana is online now
Profile CardPM
Go to the top of the page
  #2 (permalink)  
Old 01-05-2005, 08:41 AM
Beware the Robot Mafia

Group: Administrators
Location: St. Albans, Melbourne
Blog Entries: 9


Good one iodine, permissions are one of the more useful UNIX fundamentals to know of
__________________
Support MacTalk by shopping the Apple Online store via this link!
HEY INTERNET! - My Internet scrapbook.
TechieTalk - My 2c on Australian Tech News.
DMG Control Mac Apps - One More Thing Hardware Reviews - Can Touch This iPhone Apps
decryption is online now
Profile CardPM
Go to the top of the page
  #3 (permalink)  
Old 01-05-2005, 08:44 AM
Regular

Group: Regulars


Quote:
Originally posted by decryption@May 1 2005, 09:11 AM
Good one iodine, permissions are one of the more useful UNIX fundamentals to know of
Agreed. Disko should make it an article and give it a pinned topic
hawker is offline
Profile CardPM
Go to the top of the page
  #4 (permalink)  
Old 01-05-2005, 08:49 AM
Regular

Group: Forum Leaders
Location: Sydney


I should of wrote it ages ago, but considering the question was asked lastnight I thought it was a good time to do so.

And the whole numbering of the rwx etc.. Is the best way to teach it I think. Over time you will know it off the top of your head
__________________
MacBook 2.4Ghz C2D Superdrive w/ 4Gb ram, 160Gb HDD (White)
iMac 20" 2.16Ghz C2D w/ 3Gb ram, 256Mb video ram (White)
iPhone 3G 8Gb
1Tb Time Capsule
purana is online now
Profile CardPM
Go to the top of the page
  #5 (permalink)  
Old 01-05-2005, 08:55 AM
Super

Group: Regulars
Location: Somewhere Slaying Vampires


definatly should go to the articles section
very nice work
iSlayer is offline
Profile CardPM
Go to the top of the page
  #6 (permalink)  
Old 01-05-2005, 08:55 AM
Beware the Robot Mafia

Group: Administrators
Location: St. Albans, Melbourne
Blog Entries: 9


Quote:
Originally posted by hawker@May 1 2005, 09:44 AM
Agreed. Disko should make it an article and give it a pinned topic
Who said Disko needs to make it a topic, I am t3h l33t admin-man too :P
I reckon it's worthy of article status, so I'll add it to the articles bit.
__________________
Support MacTalk by shopping the Apple Online store via this link!
HEY INTERNET! - My Internet scrapbook.
TechieTalk - My 2c on Australian Tech News.
DMG Control Mac Apps - One More Thing Hardware Reviews - Can Touch This iPhone Apps
decryption is online now
Profile CardPM
Go to the top of the page
  #7 (permalink)  
Old 01-05-2005, 08:58 AM
Regular

Group: Regulars


Quote:
Originally posted by decryption@May 1 2005, 09:25 AM
Who said Disko needs to make it a topic, I am t3h l33t admin-man too :P
I reckon it's worthy of article status, so I'll add it to the articles bit.
You just never seem to be around anymore :P
hawker is offline
Profile CardPM
Go to the top of the page
  #8 (permalink)  
Old 01-05-2005, 09:04 AM
Super

Group: Regulars
Location: Somewhere Slaying Vampires


hes a lurker
Disko has been pretty quite lately aswell

if it wasnt for you and me Hawker the forums would be a graveyard
iSlayer is offline
Profile CardPM
Go to the top of the page
  #9 (permalink)  
Old 01-05-2005, 09:41 AM
Regular

Group: Regulars
Location: Berkeley, California USA


Thank you very much iodine for the submission. I've been very busy and sadly not had the time to do much here of late.

The numbering system indeed is very useful and easier to learn than the lettering system (IMHO. It's called the logic system and indeed, is very logical.

I just wanted to add one thing about "chown"

You've gone over changing ownership for single files (chown) and recursively in a directory (chown -R).

Also, to just change ownership of a directory itself, chown user:group directory (without a switch)

Doing so can make the difference of the directory and its contents loading for others in an apache document root even if the files within the directory all belong to user:user, or user:admin

Keep in mind as well that such ownership and permissions often need to be done as root as iodine was doing (sudo). Please be careful with sudo - it's very poweful =)


Anybody want to go for chgrp (change group) ?

I hardly know it myself.
macdave is offline
Profile CardPM
Go to the top of the page
  #10 (permalink)  
Old 01-05-2005, 09:45 AM
Regular

Group: Regulars


Quote:
Originally posted by islayer@May 1 2005, 09:34 AM
if it wasnt for you and me Hawker the forums would be a graveyard
ha ha too true
hawker is offline
Profile CardPM
Go to the top of the page
  #11 (permalink)  
Old 01-05-2005, 10:38 AM
Regular

Group: Forum Leaders
Location: Sydney


Quote:
Thank you very much iodine for the submission. I've been very busy and sadly not had the time to do much here of late.
I know what you mean, I get paid enough supporting worldwide customers. But sometimes its nice to be able to sit down and share some of the skills I have obtained in the last 10 or more years of industry experience.

Quote:
The numbering system indeed is very useful and easier to learn than the lettering system (IMHO. It's called the logic system and indeed, is very logical.
I think you'll find its taught this way by a number of different people etc. Its the best way I've seen it taught.

Quote:
You've gone over changing ownership for single files (chown) and recursively in a directory (chown -R).

Also, to just change ownership of a directory itself, chown user:group directory* (without a switch)
Indeed, however I could of spent ages doing all sorts of combinations. But obivously users would know (switching the last directive to a file or dir does the same thing). As always I recommend people read the man page. It describes the exact syntax and can then determine why I did various switches.

I didn't do the directory example, as per file example as its very obivous

Quote:
Keep in mind as well that such ownership and permissions often need to be done as root as iodine was doing (sudo). Please be careful with sudo - it's very poweful =)
This is the soul reason I used sudo, by using sudo along with the command I state, user is limited to what damage can be done. If I said sudo upto root and do everything as root, they could do more damage without knowing.


Quote:
Anybody want to go for chgrp (change group) ?
I could do something on that, although I tend to just vi the appropiate file, although it is nice to use the chgrp command or atleast know how to use it.
__________________
MacBook 2.4Ghz C2D Superdrive w/ 4Gb ram, 160Gb HDD (White)
iMac 20" 2.16Ghz C2D w/ 3Gb ram, 256Mb video ram (White)
iPhone 3G 8Gb
1Tb Time Capsule
purana is online now
Profile CardPM
Go to the top of the page
  #12 (permalink)  
Old 01-05-2005, 10:43 AM
Regular

Group: Forum Leaders
Location: Sydney


Quote:
Originally posted by decryption@May 1 2005, 09:41 AM
Good one iodine, permissions are one of the more useful UNIX fundamentals to know of
You should update the following url

http://www.appletalk.com.au/articles/
__________________
MacBook 2.4Ghz C2D Superdrive w/ 4Gb ram, 160Gb HDD (White)
iMac 20" 2.16Ghz C2D w/ 3Gb ram, 256Mb video ram (White)
iPhone 3G 8Gb
1Tb Time Capsule
purana is online now
Profile CardPM
Go to the top of the page
  #13 (permalink)  
Old 01-05-2005, 10:46 AM
Regular

Group: Regulars
Location: Melbourne Australia


Quote:
Originally posted by hawker@May 1 2005, 10:45 AM
ha ha too true
ive started slowly re-appearing!



Adam
adamjc is offline
Profile CardPM
Go to the top of the page
  #14 (permalink)  
Old 01-05-2005, 10:52 AM
Regular

Group: Regulars


Quote:
Originally posted by adamjc@May 1 2005, 11:16 AM
ive started slowly re-appearing!
Who are you?

:P
hawker is offline
Profile CardPM
Go to the top of the page
  #15 (permalink)  
Old 01-05-2005, 04:58 PM
Regular

Group: Regulars
Location: Canberra


Thanks iodine, its good to have this in the one spot.

I have Learning Unix for Mac OS X and the Visual quickstart guide to learning Unix, but as both take a bit of getting into - despite their straightforward approach - it is really handy to have a tutorial in the context of things you are wanting to do.

Thanks again
__________________
20" 2.16Ghz C2D iMac, G4 iBook, Lombard (2) PM 7600 40Gb iPod photo
tempestas is offline
Profile CardPM
Go to the top of the page
 
Page 1 of 2
 1  2  >
Closed Thread

Thread Tools

 
Similar Threads
 
Thread Thread Starter Forum Replies Last Post
iPhone Fever Grips the U.S. Joe90 iPhone & Mobile Phones 15 10-06-2007 02:38 PM
WWDC '06: It's coming Disko News 0 18-04-2006 11:41 AM
It's Coming... sunrisesister Desktop Computers 5 14-12-2005 08:53 AM
When are they coming? nbetts Desktop Computers 20 23-11-2005 09:10 PM