LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-30-2005, 06:28 AM   #1
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Rep: Reputation: 30
How to use Chmod


I'm extremely new to linux and I was wondering about how to change file permissions to a folder (and subsequent files) in a terminal window without logging in as root and doing it the "windows" way. I've tried "man chmod" but I don't understand the structure still.

Essentially this is what I want to do. I have a folder that I want a user say (USER123) to have read/write access to. Can someone layout the chmod structure for me please and how to use it? Thanks!
 
Old 06-30-2005, 06:38 AM   #2
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
look at this:
http://www.linuxcommand.org/lts0070.php

BUT BE CAREFULL WITH THE PERMISSIONS. The permissions are there for a reason and you should respect them. It's easy to break your system!!!

Last edited by perfect_circle; 06-30-2005 at 06:40 AM.
 
Old 06-30-2005, 06:44 AM   #3
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Original Poster
Rep: Reputation: 30
How would I break my system? I don't plan on changing and system file/folder permissions. I ran into an issue last night because I was trying to setup a profile in Thunderbird but it wouldn't allow me to write to the /.thunderbird folder. Since I didn't know how to use Chmod I had to log in as root and go to properties to adjust it. What would you recommend for something of this nature? Thanks for the link by the way.
 
Old 06-30-2005, 06:56 AM   #4
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
I don't get it. You shouldn't have files/directories owned by root in your home directory.

Use chown as root to change the ownership recursively in a folder if it's in your home directory:
Code:
chown -R <username>.<user's default group> <directory name>
I told you to be carefull because now and then , there are guys poisoned by the "windows way" and after they install linux they do something like
Code:
chmod -R 777 /
and change all permissions to rwx. Of course this will brake their system and they need to reinstall.

Last edited by perfect_circle; 06-30-2005 at 06:57 AM.
 
Old 06-30-2005, 07:14 AM   #5
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
The simple answer is, you can't.
That is, you cannot do it the "windows way".

However ... there are things you can do.
If you own the file you can use the GUI to modify it's permissions.
Right-click the file icon and select "properties" then the "permissions" tab.

You can use chmod in a terminal - you have to be root, normally, to do this.
Open a terminal, su <password>

chmod <permissions> filename

The easiest way of using this is to use the octal permissions and just change the lot. For this you need to understand binary counting.

Octal numbers are 3-bit binary.
Read permission = 4 (binary 100)
Write permission = 2 (binary 010)
Execute permission = 1 (binary 001)
For combinations of these, just add up the values.
So read/write = 6 and read/execute = 5 and read/write/execute = 7
Since you normally want to be able to see any file you can use, the most common permissions are 4, 5, 6 and 7

One of these numbers is assigned to each of the three classes from before.
So

chmod 755 foo.bar

gives read/execute of file foo.bar to group members and others, but the owner can do anything.

chmod 400 foo.bar

gives read-only access ot the owner, and nobody else can see the file or nothing.

If you look at a text file with ls -l

ls -l fubar.txt
-rw-rw-r-- ownername groupname 2224 Apr 01 22:59 fubar.txt

this means that the owner can read and write the file but not execute (fair enough since you wouldn't normally execute plain text files) Any member of the group can also read and write to it, but anyone else can only read it.

If you only want the owner to read it you do
chmod 600 fubar.txt

then the list becomes

ls -l fubar.txt
-rw------- ownername groupname 2224 Apr 01 22:59 fubar.txt

but if it is a script file, you'll want to be able to execute it, so you'd want to add execution (=1) to your permissions thus:

chmod 700 fubar.txt

and you'll get:

ls -l fubar.txt
-rwx------ ownername groupname 2224 Apr 01 22:59 fubar.txt

That should hold you.
If you think thisis sparce - go read the rules - I think it's the ninth bullet.

There are many tutorials on the web - google is your freind.
Also try "info coreutils chmod"
http://catcode.com/teachmod/
http://www.zachjorgensen.net/za/chmodtutor.html
http://www.webmasterinabox.net/kb/chmod.html

nuff said
 
Old 06-30-2005, 07:49 AM   #6
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Original Poster
Rep: Reputation: 30
The problem with Thunderbird was that I was trying to create a profile and I kept getting an permissions error saying I couldn't write to that directory. That is why I changed it.

Just out of curiousity why does

chmod -R 777 /

"break" the system and force a reinstall?

P.S. Thanks for the help, I'm a real n00b

Last edited by Centinul; 06-30-2005 at 07:52 AM.
 
Old 06-30-2005, 08:12 AM   #7
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
Quote:
Originally posted by Centinul
The problem with Thunderbird was that I was trying to create a profile and I kept getting an permissions error saying I couldn't write to that directory. That is why I changed it.

Just out of curiousity why does

chmod -R 777 /

"break" the system and force a reinstall?

P.S. Thanks for the help, I'm a real n00b
The hard answer is read the link I posted you and within 5 minutes you'll know.

the easy answer is change the permission of / and all the files that are under this directory, thus all the files in the system into 777. 777 means read-write-execute permission to the owner, the users that are in the same group and all the others.
So this basically means give read-write-execute permission to every user in the system for every file.

*EDIT*
No really, read the visit www.linuxcommand.org
It's designed for people like you.

Last edited by perfect_circle; 06-30-2005 at 08:14 AM.
 
Old 06-30-2005, 09:09 AM   #8
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Original Poster
Rep: Reputation: 30
excellent I really appreciate the help. I love expanding my knowledge of linux
 
Old 06-30-2005, 10:44 AM   #9
basilogics
LQ Newbie
 
Registered: Jun 2005
Location: Netherlands
Distribution: Suse 9.1 pro
Posts: 26

Rep: Reputation: 15
never, ever try this; chmod 000 -R root (or whatever directory)!!!!!!
i did it just for fun, it was a new installation, so no harm done. but if your system already runs for a few years.....

basilogics
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What can we do if we type chmod ugo-x /bin/chmod ?????? bunny123 Linux - Software 3 02-01-2005 08:53 PM
How do I use chmod? Adan Linux - Newbie 5 09-23-2004 04:57 PM
CHMOD in shell : chmod 777 /usr/ <---is that right? cpanelskindepot Programming 5 07-16-2004 05:37 AM
Chmod gibbylinks Linux - Newbie 1 10-23-2003 11:17 AM
chmod u+s csDraco_ Slackware 6 04-22-2003 08:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration