How to change the user name of linux

After Linux changes the user name, it is also necessary to modify the group name + home directory + UID

This only changes the username, while other things like usergroup, home directory, UID, etc. remain the same.

1. Modify user name

$ usermod -l new user old user

This only changes the username, while other things like usergroup, home directory, ID, etc. remain the same.

Note: You need to log out from the account to be renamed and kill all processes of this user. To kill all processes of this user, you can execute the following command

$ sudo pkill -u old username

$ sudo pkill -9 -u old username

2. Modify the home directory

$ sudo usermod -d /home/newusername -m newusername

3. Modify the group name

$ groupmod -n new username old username

4. Modify the UID

$ sudo usermod -u 1000 new username

5. Check

$ id The new user name can go to "Linux Command Encyclopedia" to learn more detailed Linux commands.

First of all, you need to know that when you create a user in Linux, there will be a GID in addition to the generated UID. When you modify the original user name, don't forget to update the GID as well.

Modify username:

Log in as root, then use the following commands to modify

usermod -l NewUser -d /home/NewUser -m OldUser

-l modify username

-d Modify the path used after login

-m Modify the login name and modify the directory name at the same time

Modify group name:

Following the above operation, continue to execute the following commands

groupmod -n NewUser OldName

-n Change the name of the group

How to change the username in linux: use usermod to modify the username, the syntax is $usermod -l new_username old_username.

sudo usermod -l new_user_name old_user_name

"Xingzuo.com" article, without permission ♂ reprint ♂!

Guess you like

Origin blog.csdn.net/web18334137065/article/details/126578319