How to change a username in Linux

Home > Search > How-to

The usermod command with the -l or --login command can be used to change a username. In this example, the username is changed from user1 to user2.

[root@server1 ~]# usermod -l user2 user1


The first field in the /etc/passwd file will show the new username (user2 in this example). The home directory is not changed from /home/user1 to /home/user2.

[root@server1 ~]# cat /etc/passwd
. . .


The first field in the /etc/shadow file will show the new username (user2 in this example).

[root@server1 ~]# cat /etc/shadow
. . .


Refer to the usermod command.

Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter in the box below so that we can be sure you are a human.