How to mount an old /home directory after OS clean re-install?

Solution 1:

ln -n will show you what the filesytem thinks the UID and GIDs for the users should be. Here's an example from my system.

$ ls -ln /home/
total 12
drwxr-xr-x  5  111  120 4096 Mar 15 10:11 hts
drwxr-xr-x 11 1000 1000 4096 Mar 15 12:34 oli
drwxr-xr-x  4 1001 1001 4096 Mar 13 08:46 test

In this system, oli has the right UID of 1000 but if I did something so that it was 1001, I could simply use usermod to punch it around. Let's say I want to swap oli and test's UIDs around. This is a three-hop game as two users can't share a UID. They can share a group though.

sudo usermod -u 1099 -g 1000 test
sudo usermod -u 1001 -g 1001 oli
sudo usermod -u 1000 test

One note: If your current user is one of the users in the changearound, sudo su before you start and run everything as root. Just remember that the safety's off. You don't want to get halfway through this process and have your sudo privileges bug out on you.

You'll need to play this sort of ballet until the usernames in /home/ line up with their UIDs (as shown in ls -ln /home). Alternatively you can alter all the files with a few find calls but I personally think this is a big fat waste of time. It's easier, quicker and potentially less destructive to fix this centrally through the user system.

Next time remember to check the UIDs beforehand. The --uid nnn argument on adduser will make this painless.