Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've upgraded an Ubuntu PC from 10.04 to 12.04.

Problem is all the permissions were wrong on the home folders.

So, I did the following:

sudo chown -R james:james /home/james/*
sudo chown -R james:james /home/james/.*
sudo chown -R htpc:htpc /home/htpc/*
sudo chown -R htpc:htpc /home/htpc/.*

But you end up with all the files in both folders either in james:james or htpc:htpc, depending on which way round you run the commands.

How have the become linked and how can I fix it?

As requested:

james@htpc:~$ ls -l /home
total 8
drwxr-xr-x 41 james james 4096 May 20 19:32 htpc
drwxr-xr-x 31 james james 4096 May 20 20:04 james
james@htpc:~$ ls -l /home/htpc
total 236
drwxr-xr-x  4 james james   4096 Nov 25 13:19 Desktop
drwxr-xr-x  2 james james   4096 Mar 13  2011 Documents
drwxr-xr-x  5 james james   4096 Dec 22  2010 Downloads
-rw-r--r--  1 james james    179 Nov 18  2010 examples.desktop
-rwxr-xr-x  1 james james     85 Dec 27  2010 goback
-rw-r--r--  1 james james    425 Nov 28  2010 modelines
drwxr-xr-x  5 james james   4096 Dec 27  2010 Music
drwxr-xr-x 22 james james   4096 Oct 29  2012 Pictures
drwxr-xr-x  2 james james   4096 Nov 18  2010 Public
drwxr-xr-x  2 james james   4096 Nov 18  2010 Templates
-rwxr-xr-x  1 james james    251 Dec 27  2010 testmode
drwxr-xr-x  2 james james   4096 Dec 23  2010 Videos
-rwxr-xr-x  1 james james 190672 Nov  6  2010 winetricks
james@htpc:~$ 
share|improve this question

3 Answers 3

up vote 6 down vote accepted

It is because the shell is expanding the ".*" to be ".." or up one directory.

In this case it is best, IMO, to use find

Become root

sudo -i

run find

find /home/$user -exec chown $user:$user {} \;

Change $user to the appropriate user name

In theory, chown should work with the -R and without the wildcard

sudo chown -R $user:$user /home/$user

but I think this misses the hidden or .files, which is why RoboJ1M tried ".*" which caused the problem.

share|improve this answer
    
That worked, got some errors on a few odd files though: chown: cannot dereference /home/htpc/.mozilla/firefox/hsvz7dcl.default/lock: No such file or directory chown: cannot access /home/james/.gvfs: Permission denied Some others, but they're all cannot derefence –  RoboJ1M May 20 '13 at 19:35
    
Yes you will get some of those errors. Should be fine. –  bodhi.zazen May 20 '13 at 20:07

Each folder contains a file called ... This file is special in that it points to the directory containing the current working directory. For example:

$ pwd
/path/to/dir
$ cd ..
$ pwd
/path/to

Because you specified .* as an argument, the shell expands this to every file starting with a ".", including ... This means that your operation ran on everything in the current working directory, but also the parent directory (/home). Because you specified recursive, you changed every file and directory in your /home folder to whatever ownership you specified. In fact, you may have changed the owner of every single file on your system. I would recommend running ls -l / to check if this happened - if it did, you'll probably experience issues.

share|improve this answer

I use this on my EC2 hosts to fix home folder permissions.

#fix home directories  
cd /home/  
for i in *; do   
    useradd $i  
    chown -R $i:$i /home/$i  
done  

If you do -R you should not need to use wild cards. Just chown on the top level leave the rest alone. And as others have said .* matches ..

share|improve this answer
    
darn formatting.... –  coteyr May 20 '13 at 19:30
    
it's not that hard ;) –  Rinzwind May 20 '13 at 19:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.