1832106 Members
3204 Online
110038 Solutions
New Discussion

Re: Changing UID's

 
Matthew F. Carr
Occasional Advisor

Changing UID's

I am setting up a global NIS environment and we want to change all of our UID's to a new five digit standard in our company. So basically I need an idea on how to change multiple UID's from the standard HP-UX 11.0 3 digits ones to a new five digit one (in sequential order). I know I can do this through vi'ing the /etc/passwd but I need to change all of the files associated with these users also. Maybe someone has a script to do this or even an idea for a script to do this...or, better yet, knows a simple way to do it. I am aware SAM can automate this process a bit but doing each user, one by one, is literally hours of work per server. Any help would be much appreciated! Thanks everyone!
5 REPLIES 5
Paula J Frazer-Campbell
Honored Contributor

Re: Changing UID's

Mathew

Do one in SAM and then look at sam log, you should be able to unpick what sam did and then script what you want.


Test on test server.

HTH

Paula
If you can spell SysAdmin then you is one - anon
A. Clay Stephenson
Acclaimed Contributor

Re: Changing UID's

I would suggest something like this:

Create a textfile with login and new UID, a pair per line. Call it 'userlist'.

#!/usr/bin/sh

cat "userlist" | while read USER UID
do
echo "User: ${USER} New UID: ${UID}"
usermod -u ${UID} ${USER}
done

That should do it. You also need a find script to change the ownership of all his files.



If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Changing UID's

Hi again:

You may find the attached script useful to get you started. It reads the existing passwd file and produces the following output:
useruiduid + 10000

This should help to get you started.

If it ain't broke, I can fix that.
support_5
Super Advisor

Re: Changing UID's

Hi,

I once wrote a script while I was at University to perform such a task. I was migrating a few old HP boxes into out new NIS system and all the usernames and ID's and groups needed changing, so I wrote this little script. Have a look, it works really well (although I haven't used it for 3 years! Hopefully it still works...and the code is pretty rough in places, like I said, I was at university at the time). It will also optionally modify group files and group ID's, which is handy.

One bug: I assumed when I wrote it that hashing out an entry in the password file meant that it was no longer available. Wrong, it simply means that that user id now has a username which happens to begin with a hash (#) now. eg #testuser instead of the old testuser name. Simply delete any usernames in /etc/passwd with a hash infront of them, these are old, the new user entry will be the same except with the new user id.

Just simply create a little script which will call the cfown.sh script for each user/group id you want to change and run that one night when everything is quiet. I suggest changing group id's before user id's.

Hope this helps, I haven't used it for some time now and I can't remember if there were any limitations. I think now that there are probably some better command line arguments to 'find' which would suit us better than the ones I used.

cheers,

- Andy Gray
Matthew F. Carr
Occasional Advisor

Re: Changing UID's

Hey Andy, thanks for your reply, could you shoot me that script in an email form? Thanks. My email is matthew.carr@effem.com