0

I recently migrated a server to another machine in our rack. They ownership/permissions didn't transfer when I moved /home from machine1 to /home on machine2 (both Ubuntu machines)

The user accounts successfully transfered and are all there.

I was wondering if there is a way to dynamically change all of /home to be owned by their username as currently everything is owned by root:root

I tried sudo chown -R $USERNAME: /home/$USERNAME to no avail

Any ideas?

Edit 1:

I can successfully change permissions through the use of chown -R someUser:someUser /home/someUser

My question is there a simple way to do this in bulk through the whole /home directory

Apologies for the confusion

samdunne
  • 35
  • 1
  • 6
  • First check if the user you want to give ownership exists. `grep "username" /etc/passwd` if the users exists you can run `sudo chown -R username:username /home/username`. What is the error you are getting ? – Valentin Bajrami Feb 14 '13 at 12:54
  • I get this. I was just wondering if there was some way of doing it all at once instead of one by one – samdunne Feb 14 '13 at 12:58
  • 1
    With the answers below, if your `chown` command has an ampersand after it, all of the chowns will run in parallel in the background. This may not be any faster than running them sequentially as the operation is most likely disk-bound anyway. – Ladadadada Feb 14 '13 at 13:10
  • as a side note, tar is fairly reliable way of getting all types of files and permissions across to another location intact, especially if you are using the same uid/gids from passwd and group. You can dump in one step without an intermediate file, and even remotely if root ssh is available `tar -cf - /home | ssh root@host "cd / && tar -xvf -"` – Matt Feb 14 '13 at 16:23

3 Answers3

2

You can always change home directories one by one:

cd /home
for user in *; do chown $user.$user $user -R; done
STenyaK
  • 136
  • 3
1

Previous version, but with forks, all 'chown' processes will work parallel after starting.

cd /home
for user in *; do chown -R $user.$user $user&; done
quanta
  • 50,327
  • 19
  • 152
  • 213
alterpub
  • 252
  • 3
  • 10
0

getfacl -R ... | setfacl --restore may be useful.

Are the users configured on the new system? What does "to no avail" mean? Error message? Can you change any file's owner? chown user1 testfile

Hauke Laging
  • 5,157
  • 2
  • 23
  • 40