How to change user name in Linux

Sometimes we need to alter a user account name. For this task we need to use the usermod command. The usermod command modifies the system account files to reflect the changes that are specified on the command line.

  • The syntax to change a user account name is as follows:
usermod -l
  • Example
usermod -l adrian adrian.oprea
-we will alter the user "adrian.oprea" to "adrian", so the account will maintain is privileges. Note: in case the user has sudo access you will need ot alter the sudores file to reflect the new user account name. Next step is altering the users group name: in our case the user group name is the same as the user name:
bash:$ id adrian
uid=585(adrian) gid=588(adrian.oprea) groups=588(adrian.oprea),10(wheel)
To alter the group name use the groupmod command with the -n option
bash:$ id adrian
uid=585(adrian) gid=588(adrian) groups=588(adrian),10(wheel)
And finally you need to change the home directory name:
bash:$ mv /home/adrian.oprea /home/adrian
The last step needed to be done is the restart of the /etc/init.d/autofs deamon The /etc/init.d/autofs deamon is responsible for the mount points on the system, and their corresponding configuration files or network sources known as automount maps.
bash:$ /etc/init.d/autofs restart