User id modification

Dear All,

Some of the users having the same user id and group id in my /etc/passwd file.

Now I want to change the users to have a unique user id and group id.

How can we do that. If I change this will it affect the running applications.

Rgds
Rj

Use:

usermod -u new_uid username

It might affect applications. If the user owns some directories or files on the server, then you will have to manually fix ownership on them, as after the change they will be owned by the old UID.

The only safest way would be to have one of these users to be logged out and to have no process running. Then you'll be able to modify its account ids and then change the ownership of its home directory tree. There might be issues with files that user owns in common directories like /tmp and /var/tmp as there would be no implicit way to sort out the real owner. Beware also of files stored in archives / backups as the owner would also be wrong.

Run something like this after you change the users uid to see if any files that were owned by the old uid and change them using the second command.

make note of the users uid before you change it.

find / -user olduid

This will search the entire system for all files that were owned by that user which will now be owned by the old uid.
now change ownership of the file that is owned by the old uid to the new username

chown user:group filename

Just as a thought, it may be worth it to change BOTH users to new uids. You'd have to change all the files owned by either user to the appropriate new uid. But six months from now, when you find a file that is owned by the now disabled user, you will know to ask both users who it belongs to.

1 Like

Hi All

Thanks for all ur replies.

Rgds
Rj

The problem is the OP has multiple users that have the same uid, so there's no way to automatically assign one uid to another since there's no context-free mapping.

For any given file, you can't really know which new user to assign the file ownership to because there's more than one possibility with no way to figure out which one is correct. You can probably assume if it's under the user's home directory that it's owned by that user, and maybe some other context-specific information is available, but in general there's no way to tell.

jlliagre's post didn't explicitly state that issue. FWIW, I like m.d.ludwig approach of giving all the users with overlapping uids new uids.

I assumed all files owned by the respective home directories owner were belonging to him. I guess that's a safe assumption.
For remaining files, I wrote the following which I guess was explicit enough:

So do I, that's a clever advice.