1752619 Members
4375 Online
108788 Solutions
New Discussion юеВ

Changing UID's

 
Scott E Smith
Frequent Advisor

Changing UID's

We are synchronizing UID's across the enterprise. We planned to run the usermod -u command to change the UID and then do a search of the filesystems to find orphaned files and directories. We seem to have a difference of opinion as to whether the search of filesystems is neccesary. Preliminary tests look as if it isn't.
Any ideas? We're using both 10.20 and 11.0
6 REPLIES 6
RikTytgat
Honored Contributor

Re: Changing UID's

Of course it is.

According to the manpage for usermod(1m), this command only changes the passwd entry, but does not search the file systems for files owned by the user in question.

When changing a user's uid, he won't be able to access his files anymore.

When performing the command 'ls -l', orphaned files and directories show with the uid and gid instead of username and groupname for unknown uids and gids.

When changing uids for non-standard unix users only, one might restrict the search to the user's home directories.

Hope this helps,
Rik
Scott E Smith
Frequent Advisor

Re: Changing UID's

I tested the theory. I performed a usermod - u 3001 loginname and it changed the UID to 3001 from 104. A subsequent find / -user 3001 listed all of the files I previously owned (username was displayed). Another find command using the old UID produced no results. While I wouldn't expect the system to search and replace UID's with usermod. I guess I may have demonstrated that the association to the username remained with only the UID changing. I'd like to avoid the search issue if at all possible. Clear as mud?
RikTytgat
Honored Contributor

Re: Changing UID's

Actually, the owner of a file is stored in the inode structure as a uid. The association with the username is done by the command that prints the username (i.e ls, find, ...) using the getpwuid(3) call.

So, when a user's uid is modified, the getpwuid(3) call fails, which results the calling programs (ls, find, ...) to print the uid (numeric) instead of the username.

Rik.
RikTytgat
Honored Contributor

Re: Changing UID's

Actually, the owner of a file is stored in the inode structure as a uid. The association with the username is done by the command that prints the username (i.e ls, find, ...) using the getpwuid(3) call.

So, when a user's uid is modified, the getpwuid(3) call fails, which results the calling programs (ls, find, ...) to print the uid (numeric) instead of the username.

Rik.
Scott E Smith
Frequent Advisor

Re: Changing UID's

IF that's the case then why did the find search display the correct user name instead of the old UID number?
RikTytgat
Honored Contributor

Re: Changing UID's

Good question.

Did the usermod command take a long time to execute? If it actually does scan all mounted file systems, it should take considerable time to execute.

Another possibility is that usermod automatically changes all files under the user's home directory. This behaviour is not in the manpage for the command.

Finally, I can assure you that the inode is the place where the owner of a file stored, and the association is done using getpwuid(3).

Rik