linux change username

藏色散人
Release: 2019-06-06 10:01:55
Original
21947 people have browsed it

Sometimes, for some reasons, we may need to rename the username. We can easily change the username and corresponding home directory and UID.

linux change username

Modify username

We use usermod to modify the username. The syntax is,

$ usermod -l new_username old_username
Copy after login

For example, suppose we have a user named dan who wants to rename to susan, then execute the following command in the terminal:

$ sudo usermod -l susan dan
Copy after login

This will only change The username, while other things such as user group, home directory, UID, etc. remain unchanged.

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

$ sudo pkill -u dan
$ sudo pkill -9 -u dan
Copy after login

Modify the home directory

To change the home directory at the same time, we need to add the -d option while executing the usermod command,

$ sudo usermod -d /home/susan -m susan
Copy after login

Change User UID

Execute the following command to modify the user UID.

$ sudo usermod -u 2000 susan
Copy after login

Here 2000 is the user’s new UID.

Modify the user group name

To change the user group name from dan to susan, we need to use the groupmod command. Use the following command to modify the user group name.

$ groupmod -n susan dan
Copy after login

After making the modification, you can use the id command to check.

$ id susan
Copy after login

Recommended video tutorials: "Linux Tutorial"

The above is the detailed content of linux change username. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template