# How to change permissions for a group of directories and ...

## Trisha

I moved all the files from my old computer on to my new one running Gentoo but I'm not recognized as the owner of my files.  So far I have been right clicking, choosing Properties and giving myself Write permission so I can use them.  That's getting to be a lot of work though - way too many directories and subdirectories of files to change like that.  

Is there a way using chmod, or something else from the command line to give myself read, write and execute permission on all files in my user directory?  For example how can I do this with myself as user trisha so that I can do whatever I need to with all files in /home/trisha/?

Thanks

----------

## papal_authority

Something like 

```
chown -R trisha /home/trisha
```

 should work  :Very Happy: 

----------

## Trisha

Thanks - can I su to root to do it or do I have to be actually logged in as root?

Also, someone else had told me to do:

chown -R trisha:users /home/trisha

But it didn't work.  I did that with su.  

And what is the difference between the two?  What did the 'users' part try to do that didn't work, or was it that  I wasn't really logged in as root?

----------

## fleed

You don't need to be logged in as root, su is fine. The part after the : is telling chown what group to use, and users should be fine. What error message did you get?

----------

## Trisha

I don't get an error - it just doesn't work.  Both with 

chown -R trisha:users /home/trisha 

and

chown -R trisha  /home/trisha 

I do it, then go and check some files and directories, and I still don't have write access.

----------

## kashani

I'd do both chown and chmod just in case.

chown -R trisha: /home/trisha

# that : after trisha pulls the proper group and saves you some typing.

chmod -R 755 /home/trisha

# this might be much more than you want. For instance your .ssh/ dir shouldn't be 755 so you may just want to do the dirs separately.

kashani

----------

## groovin

owning a file doesnt always mean you have write access to it. chmod like kashani suggested.

you should do 

man chmod

and read up on permissions. man pages are boring, but usually educational =)

----------

## Trisha

 *Quote:*   

> owning a file doesnt always mean you have write access to it. chmod like kashani suggested.

 

Write permission was one of the main things I wanted, since I am not able to edit existing files without it.

Also, I was just even trying to move entire directories (with many subdirectories) to a different location and I get a message saying I don't have permission to do that.

I've done chmod before, but just on servers to change permissions on certain files for web sites.  I can't imagine having to go through and do each directory and subdirectory separate though - I have way too many.  

Is there any danger in just doing chmod -R 755 /home/trisha, so I would have write permission on all files?

----------

## papal_authority

 *Trisha wrote:*   

> Is there any danger in just doing chmod -R 755 /home/trisha, so I would have write permission on all files?

 

Not really any danger with a user's home directory, but I'd still do each directory seperately as kashani suggested. Looks like you may owe him a spinach pizza  :Razz: 

----------

## kashani

It's good to know papal authority really is infallible.  :Smile: 

Seriously you probably won't break anything, but if you use ssh keys those will break since 755 permissions are a bit much. You might try 

chmod -R +w /home/trisha

That should add write access for you the owner to each file without affecting anything else. That should be less intrusive.

kashani

----------

## Trisha

If I tried to do every directory separately it might take hours, which was what I was trying to avoid to begin with.  

What would be the purpose of doing it that way?

I don't get the pizza thing - but I have had spinach on pizza although I don't normally like vegetables  on pizza, but I've had spinach and mushroom pizza before and I liked it.  Damn it!  Now you've make me hungry!!   :Smile: 

----------

## Trisha

I don't know what ssh keys are, so I doubt that I use them.  What are they for anyway in case I might be using them?

The only thing I know about ssh is that my hosting company doesn't allow telnet access anymore, so for certain things, if I want to use them I would need to install putty for ssh access.

----------

## Trisha

Ok, I saw kashani's sig line now, so I get the pizza thing - and I'm still hungry!

So chmod -R +w /home/trisha  will only add write access, but not change the read or execute permissions from what they are now?

----------

## kashani

Starting over here, first you need to make sure you're the owner of all the files. 

chown -R trisha: /home/trisha

This can be run without causing any problems. The -R is for recursive so all files, sub folders etc get owned to you. Obviously you'll need to do that as root since you're changing ownership.

chmod -R +w /home/trisha

This should be fine as well as I just did some simple tests to make sure. Again the -R is recursive and does all the files and sub folders. 

Lots of people will say read the man pages, but I would recommend "Unix for the Impatient" as a better place to start depending on how much you wnat to get into Linux. It's probably $40-50, but really covers the basics well of getting around your *nix box from the command line.

The pizza thing was a bit of a joke. I was living in California and really missed stuffed spinach pizzas and I was also getting a number of AIM and privates messages for help from the Gentoo forums. Since I normally fix friends computers for "pizza and beer" I figured it was only fair that the rest of the people should have to play along. One nice fellow who I spent a few hours with working on his mail server did actually send me two pizzas which was pretty darn nice. 

Since I moved back to Chicago in June I'll have to think of something else for people to send me. Maybe sushi.  :Smile: 

kashani

----------

## Monkeywrench

755? What an ugly hack. I would feel horribly icky if everything in my home dir was 755...

Kashani: your command would set write permissions for all users.

try this instead:

 *Quote:*   

> chmod -R u+rw /home/trisha

 

The command adds read and write permissions only for the owner for every file in /home/trisha... which is way more secure than blindly applying 755 to every single file.

Be paranoid!   :Cool: 

----------

## Trisha

kashani - I did the chown part already, so I should be ok with that.  I'll try the chmod part in a little while here.

I asked a while back in another forum here for  book suggestions on Gentoo or linux. As far as  I can tell, there are no Gentoo books yet.  So you recommend "Unix for the Impatient"?  I might try it.  Man pages are generally written way over my head.  I don't expect to be an expert on linux/unix, I just need to learn what I need.  Not that I don't like learning - I have my hands full right now with learning.  I'm just a web developer/designer who got tired of Windows and was determined to switch to linux to avoid it.  So I have to learn what I can along the way and still get my regular work done.  

Chicago huh?  I'm originally from Southern Illinois, in St. Louis now.  I bet when you're not drinking beer with your pizza, you drink 'pop' with it!   :Wink: 

----------

## Trisha

Monkeywrench - right now I'm the only user on this computer, and most likely always will be so that may not be an issue. 

Would chmod -R u+rw /home/trisha take away execute permission from files that already have it?

----------

## kashani

Nope and you can test to make sure.

touch test.txt

chmod 777 test.txt

ls -la test.txt

chmod -w test.txt

ls -la test.txt

at this point you should see that the user can not write to the file any more. The u specificies user permissions which is also the default. So u+w is the same as +w. 

chmod +w test.txt

now things are back to normal.

chmod +w test.txt

no change so you're good.

kashani

----------

## Monkeywrench

 *Trisha wrote:*   

> Monkeywrench - right now I'm the only user on this computer, and most likely always will be so that may not be an issue. 
> 
> Would chmod -R u+rw /home/trisha take away execute permission from files that already have it?

 

Well, it's just good practice in general. I don't plan on crashing into a tree with a car soon, but I still wear seat belts.

And no, the command I supplied doesn't take any permissions away. Here's a quick breakdown of what I gave you:

chmod ----the command

R ----this just makes it so the command applies to all files in a directory and subdirectories, and the files in the subdirectories (and so on)

u ----this means only for the owner of the file, which is you. if this was 'g', then the command would apply to the group that owns the file, which is the 'users' group. if it was 'o', it would apply to all other users.

+ ----this means only add permissions. if it was a '-', it would have taken away read and write permissiosn.

rw ----this means read and write. adding 'x' would have added execute permission. execute permission is required for programs and scripts and such. execute permission is  also required for directories so you can access them.

Does that make sense?

----------

## groovin

fixing comps for beer and pizza? thats a great idea!! if i had beer and pizza for every computer ive fixed, damn, i would weigh 400lbs and never have to buy myself dinner!

----------

