1833866 Members
2522 Online
110063 Solutions
New Discussion

Re: Changing userids

 
SOLVED
Go to solution
Mark Nierth
Advisor

Changing userids

I've been tasked to change all userid's to a new standard. I've got over 30 HP-UX 11.11 non-trusted servers. The total number of userids that have to be changed is over 1000. Not only do I have to change the userid and home directories, but copy the contents of their old home directory to their new home and change all files they may have created outside of their home directory, with the new owner.
Anyone have any scripts that may help ?
4 REPLIES 4
Patrick Wallek
Honored Contributor
Solution

Re: Changing userids

You should not need to actually create any new user ids.

You must remember that ownership is based on the UID number. Say my id is patrick and I want to change it to p12345. I would recommend using the 'usermod' command. I would do:

# usermod -l p12345 patrick

Now I keep the same UID, so all files that previous showed patrick as the owner now show p12345.

Now if you want to move their home directory as well, you can add the '-m' and '-d' options as well.

# usermod -l p12345 -d /home/p12345 -m patrick

That **should** change my login id from patrick to p12345 and move my home directory from /home/patrick (or whatever it was) to /home/p12345.

I would advise studying the man page for usermod as they talk about some permissions requirements when using '-m'.
DCE
Honored Contributor

Re: Changing userids



usermod is the quickest.

If you want to farm it out to a summner intern, you could have them use SAM. It is not as efficient (and some people do not like sam at all), but it does start a background process to complete the change, and is menu driven
James R. Ferguson
Acclaimed Contributor

Re: Changing userids

Hi Mark:

Have a look at the manpages for 'usermod', 'chown' and 'find'. You could easily construct a script driven by a file containing the 'uid', OLDNAME and NEWNAME associations; something link:

while read UID OLDNAME NEWNAME
do
usermod -u ${UID}-l ${OLDNAME} ${NEWNAME}
find /app -user ${OLDNAME} -exec chown ${NEWNAME} {} \+
done < /tmp/users

...where the driving '/tmp/users' input might look like:

# cat /tmp/users
1000 oldmark newmark
1001 oldsam newsam
1002 userx userxprime
1003 usery useryprime

Regards!

...JRF...
Mark Nierth
Advisor

Re: Changing userids

Thanks guys...I didn't realize such a command existed.
Beers and 10 points all around !!!!