UID mismatch upon installing a new distribution

Locked out of /home after installing a new distro? Here's how to fix it. …

THE PROBLEM
Traditionally, Linux user ID and group ID numbers (UIDs and GIDs) began at 500. Some distributions begin numbering at 1000 or 1500, however, which can cause problems. For example, imagine you've been running Foo Linux, and your UID is 500. ls -l shows your files belong to you, but what is really happening internally is that the files are marked as belonging to user 500 (see ls -n), which is associated with you in /etc/passwd.

So far so good. But now you replace Foo Linux with Bar Linux, using your existing /home partition and creating a user with the same name. If Bar Linux assigns you the UID 1000, you will be locked out of your own /home — this because you are now UID 1000, but your files continue to belong to UID 500.

PREVENTION
Before installing a new distribution, make a note of your current users' UIDs. You can find this information in /etc/passwd, in Webmin (System – Users and Groups), or in your distro's user administration tools. Investigate how the new distro numbers UIDs. If its default numbering scheme is incompatible with your existing UIDs, decide how to handle this issue.

The obvious solution is to manually assign the appropriate UIDs when creating users during the new distro's installation. This is one case where the obvious solution isn't the best, however. Not all distros's installers offer the option of manually selecting UIDs, so this method cannot be relied upon. Further, the distro's developers presumably had a reason for numbering UIDs as they do. Finally, this method doesn't scale well. As time goes on and you add users, you may forget to manually assign them consecutive UIDs, and you will wind up with (following our example above) some UIDs in the 500s and others in the 1000s. Such a system will work, but creates needless complexity and confusion for you the administrator.

What I do is create one user during installation, giving it a unique name. Once booted into the new distro, I can chown and copy files as needed, change the username as desired, and create new users. Webmin is good for working with users and groups, and the command line is good for chowning. For example, the following (performed as root) searches the entire device for files belonging to UID or GID 500 and chowns them to 1000:

# find / -user 500 -exec chown 1000: {} ;
# find / -group 500 -exec chown :1000 {} ;

CURE
But let's say you didn't do that and are now locked out of /home. Get to a root prompt (Ctrl-Alt-F1 on a running system or boot into the distro's failsafe mode) and log in as root. Note the previous distro's UIDs by comparing the output of ls -l /home with ls -n /home. You may also see junk files that were created by the problem; they may be deleted.

Review /etc/passwd to find your new distro's UIDs and GIDs. Now search and chown files as shown above, and move them if needed. Problem solved.

Advertisements

About Warren Post

So far: Customer support guy, jungle guide, IT consultant, beach bum, entrepreneur, teacher, diplomat, over-enthusiastic cyclist. Tomorrow: who knows?
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

2 Responses to UID mismatch upon installing a new distribution

  1. Pingback: Installing a new distribution | A maze of twisty little passages

  2. Pingback: Installation notes, Linux Mint Debian 201204 | A maze of twisty little passages

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s