Change user name in CentOS/Ubuntu

Change user name in CentOS/Ubuntu

1. Change the name of the current user in CentOS and Ubuntu, execute the following command with root user authority

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

2. After the modification, this step has not been completed yet. You need to modify /etc/passwd and /etc/shadow to change all the places containing OldUser to the name of NewUser.

3. Also need to modify the user group information

groups

View the user group to which the currently logged-in user belongs.
Usually the user name of the user combination is the same. If you need to modify it, execute the following command:

groups Username

View the group that the Username user belongs to and the members in the group.

If the new user name does not exist in the user group, and you want to change the user group name and the user name to the same, you need to modify the /etc/group file and change the original OldUser name to NewUser;

Or add a new user group (the group name is the same as the new user name), and then execute the following command on all files in the current user's home directory:

chgrp [-R] NewGroupName *

That is, the user group that all files in the Home directory belong to is changed to this new NewGroupName.

Guess you like

Origin blog.csdn.net/qq_27198345/article/details/109592256