Migrate to a new user home

I’ve had multiple issues with the configuration of the current user. Under a new user account these are solved. Now I want to move (not copy, because of disk space) all data from the old user to the new user. I also want to selectively move some of the unproblematic application setting files over to the new user.

To do this, How can I make the entire user folder of the old user read and writable for the new user?

Asked By: Max N

||

Change the ownership of the home directory using chown to the new user.

chown -R newuser:newuser /home/olduser
Answered By: Panki

I’m going to guess that the "multiple issues" are actually related to application specific configuration. A vanilla account shouldn’t have anything that depends on the location of the home directory.

The problem you’re describing though is difficult to resolve without carrying across any issues. Copying non-"dot" files, along with the standard shell startup files might be a good start, but it’s still possible you’ll either miss important dot files or carry across too much. It’s going to have to be a bit of a trial and error solution.

Let’s assume you’ve already created the new account. For convenience I shall use variables to identify the old and new user directories. Perform all this as root:

olduser=olduser          # For example, « olduser=sarah »
newuser=newuser

oldgroup=oldgroup        # For example, « oldgroup=sarah » or « oldgroup=users »
newgroup=newgroup

oldhome=/home/olduser    # For example, « oldhome=/home/sarah »
newhome=/home/newuser

Move files from the old directory to the new:

mv "$oldhome"/* "$newhome/"
mv -f "$oldhome"/.{bashrc,bash_profile,profile,ssh} "$newhome/"

Review the remaining files, and move (mv) those you want to keep:

ls -RA "$oldhome"

Finally, change the ownership and group for the new user:

find "$newhome" -user "$olduser" -exec chown "$newuser" {} +
find "$newhome" -group "$oldgroup" -exec chgrp "$newgroup" {} +
Answered By: roaima
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.