How to rename a user in Linux

In this article, we will see how to rename a user in Linux with examples.

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

How to rename a Linux User

1. First create a user in Linu.

sudo useradd test1

How to rename a user in Linux

2. Syntx to change username in Linux:

usermod --login new_username old_username

3. Now create a directory for newuser(In my case test2 is the new username for test1). So, create a directory in /home directory

cd /home

sudo mkdir /home/test2

4. Now rename Linux user(test1 to test2) using below command.

usermod --login test2 --move-home --home /home/test2 test1

5. We can modify group for user test2.

groupmod -n test2 test1

Video tutorial for the same task: