It’s not trivial to do. Here are some things to consider:
To find out the UID of your user, use this command:
id username
where you would substitute username
with your user’s name.
It will give you a UID and GID, as well as a list of groups your user belongs to.
Do this on all of the computers and note it. You want those two numbers to be the same across all of your computers.
Now, to change the UID and GID of your user and his/her group, you have to do it in two steps. The first is to change the group’s GID, then change the user’s GID and UID. You can use the following two commands:
groupmod -g new_GID groupname
usermod -u new_UID -g new_GID username
where you would substitute new_GID
with the new GID, and groupname
with the name of the group for which you change the GID, and new_UID
with the new UID, new_GID
with the new GID (the same one as in the previous command), and username
with the your user’s name.
You can verify that you’ve done it correctly using the id
command, given above.
However, using these commands on a running system is not a good idea, because there are two undesirable side effects:
- The UID and GID for processes that are currently running will not change.
- The UID and GID for the files on your system will not change.
There are also other things to keep in mind:
- If there are other users in the group for which you’re changing the GID, their group membership will not be updated, you need to do this manually.
- If the UID or GID is already used, you will need to change that one first to something else.
It is best to do any of this in a chroot
, or in a TTY, logged in as root and logged out with any other user. You will have to manually change the UID and GID for all the user owned files on your computer. Doing so requires extreme caution, because if your mess up, it’s very difficult to reverse it.
You could do it with the find
command, but its syntax is not very intuitive. You also need to keep in mind any symbolic links, which might be broken.
These are the commands:
find / -uid old_UID -exec chown -v -h new_UID '{}' \;
find / -gid old_GID -exec chgrp -v -h new_GID '{}' \;
where you would substitute old_UID
, new_UID
, old_GID
and new_GID
with the appropriate numbers. You may want to do a dry run without the -exec
option (and everything following it).
That should be it, but before you do it, make sure you understand these commands (read the manuals), and have somebody review these steps, in case I forgot something.
As always, keep a good backup in case something goes wrong.