How To Change or Rename Username and User ID In Linux? – POFTUT

How To Change or Rename Username and User ID In Linux?


The problem is we want to change the already created user name or user id. As we know there is a lot of configuration those rely on the user id like permissions. We will use usermod command to make this change. Keep in mind this changes will effects system wide.

List User Info

Before starting to big changes we will list users detailed info with cat command like below.

$ cat /etc/passwd | grep ismail
List User Info
List User Info
  • test is our user name for this operation
  • 1000 is the current id of our test user.

Change User Name

We will change username with the following command by providing new username. We will provide the -l option with the new username and old username. In this example we will change username ismail into ali.

$ sudo usermod -l ali ismail
  • usermod is command we issue to chage
  • -l ali is the new username
  • ismail is the original username

Change User ID

Another opportunity is changing the user ID. Previously we have listed user information of the ismail . We know that the user id of the ismail is 1000. We will use -u option and the new user id with the user name. In this example we will change the user id of ismail into 1010

$usermod -u 1010 ismail
  • usermod is command used too
  • -u 1010 is new user id provided for the user
  • ismail is the user whose id will be changed.

Check It Again

After these steps we need to the if there is a problem or everything is OK. We will list user information again with the cat command like below.

$cat /etc/passwd | grep test
  • test2 is new username but home directory stays the same
  • 1010 is the users new id
LEARN MORE  How To Delete Remove User Accounts In Linux?

 

How To Change or Rename Username and User ID In Linux? Information

How To Change or Rename Username and User ID In Linux? Information
How To Change or Rename Username and User ID In Linux? Information

Leave a Comment