How to change a username in Linux

Home > Search > How-to
  by

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
user2:x:1002:1002::/home/user1:
. . .

 

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

[root@server1 ~]# cat /etc/shadow
user2:!:17014:0:99999:7::18350:
. . .

 

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.




Comments