Users – How to Rename a Unix User Account

administrationusers

I installed Ubuntu on a computer that is now used by somebody else. I renamed the account with her name, but it only changes the fullname, not the user name, which is still displayed in the top right (in the fast-user-switch-applet). Is there a command to rename an Unix user account?

I've thought of creating a new user account with the new name, and then copying everything in the "old" home to the home of the new account. Would it be enough? But then I think the files would have the old account's permissions' owner? So should I do chown -R newuser ~?

Is there a simpler/recommended way to do this?

Best Answer

Try

usermod --move-home --login <new-login-name> --home <new-home-dir> <old-login-name>

The --move-home option moves the old home directory's contents to the new one given by the --home option which is created if it doesn't already exist.

If you want the primary user group to match the new-login-name, add --gid <new-login-name> to the command above, but the group must be pre-existing.

See the man page for more info:

man usermod
Related Question