Linux – How to rename a Unix user

linuxunixuser-accountsuser-management

I have a user named hedgehog and I want him to be named squirrel, but I don't want to change his numeric user ID.

How can I accomplish this?

Best Answer

Under Linux, the usermod command changes user names. It modifies the system account files to reflect the changes that are specified on the command line.

To change just the username:

usermod --login new_username old_username

To change the username and home directory name:

usermod --login new_username --move-home --home path_to_the_new_home_dir old_username

You may also want to change the name of the group associated with the user:

groupmod --new-name new_username old_username