Home  >  Article  >  Operation and Maintenance  >  linux change username

linux change username

藏色散人
藏色散人Original
2019-06-06 10:01:5521915browse

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

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

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

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

Change User UID

Execute the following command to modify the user UID.

$ sudo usermod -u 2000 susan

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

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

$ id susan

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!

Statement:
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
Previous article:linux open file commandNext article:linux open file command