Operating System - HP-UX
1836461 Members
2344 Online
110101 Solutions
New Discussion

Re: What's the best way to RENAME user?

 
SOLVED
Go to solution
yyghp
Super Advisor

What's the best way to RENAME user?

Because we want to following the new naming convention, some of the usernames wanted to be changed...
I'd like to know what's the best and safe way to RENAME them without any risk...
After the username changes, is there any special steps to deal with those files owned by this user ?
What kind of things I need to pay attention when I do this change ?
Thanks !
12 REPLIES 12
A. Clay Stephenson
Acclaimed Contributor

Re: What's the best way to RENAME user?

There is no problem renaming users; simply make the changes. However, if you are changing UID's then you need to chown all the files owned by the user.
If it ain't broke, I can fix that.
Patrick Wallek
Honored Contributor

Re: What's the best way to RENAME user?

I would go with the 'usermod' command.

# man usermod

# usermod -l new_login old_login

This should change /etc/passwd AND /tcb/files/auth/?/login_name if your system is trusted.

Since permissions are based on the UID number rather than the actual name, you should be OK in that respect.

I would do this during *NON-WORKING HOURS* and make sure your users know that when they come in for work on whatever the next day is, that their user ids will have been changed. Also make sure your help desk know (if you have one) knows about. I would also create a list with each users old id and their new id so you, or your help desk, can get the users pointed in the right direction ASAP.

I would also make sure you don't have any password issues. As far as I know usermod doesn't change the password, but it is something to keep in mind.

Good luck.
John Dvorchak
Honored Contributor

Re: What's the best way to RENAME user?

I think to rename a user the best way would be to use usermod (man usermod). As far as the files and directories, as long as the uid number remains the same, which it will with usermod, the file/direcory owner will automatically change.

You can also use usermod to change the home directories, if you want, but that won't automatically copy the files to the new directory. You may have to play with this a little, but I think you will find usermod the way to go. I am sure with just a little thought you could script this easily.


Good luck
If it has wheels or a skirt, you can't afford it.
Sridhar Bhaskarla
Honored Contributor

Re: What's the best way to RENAME user?

Hi,

*uid* and *gid* are the ones that matter not the names.

If you are just renaming the user (not changing the uid), then it is safe to do it. You will see the permissions changed automatically to the new user name. The inode information doesn't contain the user name but only the uid.

On the contrary it doesn't work the same way if you change the uid. Once the uid is changed, then you will have to individually change the ownerships of the files.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
yyghp
Super Advisor

Re: What's the best way to RENAME user?

how about using SAM "modify" user to change the username?
which way will be better ? SAM or usermod ?
Thanks !
A. Clay Stephenson
Acclaimed Contributor

Re: What's the best way to RENAME user?

Whichever you are more comfortable with. If I were doing many of these, I would create a text file with the old and new names on the same line and write a script to call usermod repeatedly.
If it ain't broke, I can fix that.
John Dvorchak
Honored Contributor

Re: What's the best way to RENAME user?

I believe that sam uses usermod, or a variant, to accomplish the same thing. So the real question is which do you want to use? Use the command line (quick) or sam (slower)? Or the 3rd not mentioned option of editing the passwd file directly. I DO NOT recommend this but if you decide to edit the password file DO NOT USE VI. Us vipw instead, because that's what it is for and it does a sanity, syntax check before writing and exiting the password file.
If it has wheels or a skirt, you can't afford it.
yyghp
Super Advisor

Re: What's the best way to RENAME user?

yes, changing the home directories because of this modification will be a little trouble, wants to create a new home directories with new user name, and move files from the original one to the new home...
Patrick Wallek
Honored Contributor

Re: What's the best way to RENAME user?

I wouldn't create new home directories, I'd merely rename (mv) the current ones.

I'd do this with a script as Clay suggested.

Create a text file with the old user name and new user name on one line.

Then script it so that for each line in the file you do:

usermod -l ${new_name} {old_name}
mv /home/${old_name} /home/${new_name)
Con O'Kelly
Honored Contributor
Solution

Re: What's the best way to RENAME user?

Hi

You can also use the usermod command to accomplish the whole thing.

# usermod -d -m -l

This will change the username, create the new home directory and move all the files.

Cheers
Con
yyghp
Super Advisor

Re: What's the best way to RENAME user?

Hi con,

yes, i tried yours just now, and i think i need to add:

# rm -R

After:
# usermod -d -m -l

is that right ?
Con O'Kelly
Honored Contributor

Re: What's the best way to RENAME user?

Hi

Yes thats correct, it will leave the old home directory. You can remove it once you are sure everything has been properly copied to the new home directory.

Cheers
Con