Moving users' home/ directories from one machine to another, or from one server to another, can be tricky.

Here is a simple script that can make sure ALL the files in each users' home directory is actually owned by the proper user after a transfer. This script should be run in /home on the new, target machine. It presumes the users have been created and their home directory file contents copied over

The script needs to be run as root, and it is important to know that any unusual ownership (such as for specific applications requiring a subset of files owned by other users) will be overwritten with a single default.

This script works for Group-Per-User distributions, like Redhat.


# This script is used when transferring home directories to #a new machine.
# This script should be copied to the /home/ directory and
# run from there. The individual username should be supplied -
# that of the user whose home directory is to have it's ownership set.
# Ease run will recursively set the ownership of all 
# files in a home directory to the actual new user who
#  will own the directory. 

chown -R $1:$1 $1
ls -lAX $1/

The script is executed from a terminal like so:

 # Make sure script is executable:
 chmod u+x ./correct_home_ownership.script

 # Run it

See also