Operating System - HP-UX
1748256 Members
3655 Online
108760 Solutions
New Discussion

Changing username and UID on HP-UX based servers

 
Waqar Razi
Regular Advisor

Changing username and UID on HP-UX based servers

There has been some changes in the naming convention of the user names on the Unix servers. Before usually the username was created using the first name and any UID above 100 could be assigned to it. Right now, there is some change in the naming convention and the usernames of the staff members should be the first inital and the last name. Also the UID of the staff members should be something above 20000. 

 

I have been asked to implement these changes on the HP-UX based servers.

 

Can someone please advice me the best way to accomplish this task? I want to change the usernames of the existing users and also want to change the UID of these accounts as well so that they start with 20000.

 

Any help will be highly appreciated.

 

Regards,

 

Waqar

4 REPLIES 4
Bill Hassell
Honored Contributor

Re: Changing username and UID on HP-UX based servers

This is a trivial task if the passwd file just has a couple of users. But if you are looking at dozens or hundreds of users, the task not only very labor intensive as well as a bad idea. The task to change the login name and UID is simple. But once that is done, all the files owned by the original username will be orphans, that is, a long listing will show no onwer name but just the old UID. So all the files owned by the original UID must be changed to the new UID. For the HOME directory, this is fairly simple, but the user may have directories and files in /tmp, /var/tmp, and any number of other directories where files/directories may have this user's old UID.

 

To perform an accurate UID change, you my have to scan every file/directory on the system and make the change using find and -exec. For a small workstation, this may take only a minute or two, but for a large server, each UID find might take 30 to 90 minutes. During each find, the disk load will be also quite high which affects other programs and applications. Or through a good understanding of where each user's files/directories are located, yu could write selective find commands to speed things up.

 

This type of change can create an unstable system, especially during conversion, and unless carefully scripted, some really serious mistakes could cripple the system.



Bill Hassell, sysadmin
Dennis Handly
Acclaimed Contributor

Re: Changing username and UID on HP-UX based servers

>I want to change the usernames of the existing users

 

This is trivial and can be done quickly.  You may want to do this as phase 1.

 

>you may have to scan every file/directory on the system and make the change using find and -exec.

 

If the number of files to scan and the number of users increase, it may make sense to write a custom program or perl script to do all of the users at the same time.

 

I'm not sure if the chown would also be expensive, so that you might want to do that when you're in that directory.

Rather than collecting the commands and run the script later.

Waqar Razi
Regular Advisor

Re: Changing username and UID on HP-UX based servers

THanks for your help. Could you please provide me a script to  scan every file/directory on the system and make the change using find and -exec commands.

 

ANy help will be highly appreciated.

 

 

Dennis Handly
Acclaimed Contributor

Re: Changing username and UID on HP-UX based servers

>scan every file/directory on the system and make the change using find and -exec commands.

 

For a particular OLD_UID/NEW_UID pair you can do:

   find / -user $OLD_UID -exec chown $NEW_UID {} +

 

If you're changing the GID too, you can tack that onto the chown.

Note: This will also attempt to change NFS files, which you might want to exclude.