Rename a user/Change a username

What is the recommended method to rename a user or change a username?

Or is it a case of add new, remove old, rename home directory, chown?

Thanks.
 
Just use vipw(8) and change the username and home directory. Rename the home directory itself and you're done. You may also want to rename the corresponding group name.
 
As with all things *nix, there are several roads leading to Rome ;)

Keep in mind that your script might do something really unexpected if the user doesn't exist.
 
[CMD="ggg"][/CMD]I want to point out that chpass(1) does not work to change the name of an account as suggested.

I am testing under FreeBSD 9.0, and after editing the name of the account using this command, the result is a new record in /etc/passwd with the new name (the rest of the fields containing the same data as the original record), and the original record remains unchanged.

So the result is two records with the same user id, which is incorrect.

Any other possibility besides manually editing?/etc/passwd and, of course, /etc/group (to change the name of the corresponding group plus any other group that the account might be part of.

Cheers.
 
This thread is old, but I was searching for how to do this and came across a method I preferred, using pw(8).

pw usermod -n oldname -l newname -d /usr/home/newname
pw groupmod -n oldname -l newname
mv /usr/home/oldname /usr/home/newname
chown -R newname:newname /usr/home/newname


Warning: I've only done minimal testing so far.
 
Back
Top