Home  >  Article  >  Operation and Maintenance  >  How to update user information in Linux system

How to update user information in Linux system

WBOY
WBOYOriginal
2024-02-26 15:09:30570browse

How to update user information in Linux system

How to modify user information in Linux system

In Linux system, each user has his own user account information, including user name, user ID, group ID, home directory, etc. If you need to modify user information, you can do so through the command line tool. The following will introduce the specific steps and sample code on how to modify user information under the Linux system.

Step 1: View the current user information

First we need to confirm the user information to be modified. You can use the following command to view the detailed information of the current user:

$ id

Step 2: Modify user information

1. Modify user ID and group ID

You can use the usermod command to modify the user ID and group ID. The command format is as follows:

$ sudo usermod -u <新的用户ID> -g <新的组ID> <用户名>

For example, the command to modify the ID of user testuser to 1001 and the group ID to 1001 is as follows:

$ sudo usermod -u 1001 -g 1001 testuser

2. Modify the user name

If you need to modify the user name, You can use the usermod command with the -l parameter to modify it. The command format is as follows:

$ sudo usermod -l <新的用户名> <旧用户名>

For example, modify the user name of user olduser# The command of ##newuser is as follows:

$ sudo usermod -l newuser olduser

3. Modify the user’s home directory

If you need to modify the user’s home directory, you can use the

usermod command with -d parameters are modified, the command format is as follows:

$ sudo usermod -d <新的家目录> <用户名>

For example, the command to modify the home directory of user

testuser to /home/newdir is as follows:

$ sudo usermod -d /home/newdir testuser

4. Modify the user login Shell

If you need to modify the user's login shell, you can use the

usermod command with the -s parameter to modify it. The command The format is as follows:

$ sudo usermod -s <新的Shell路径> <用户名>

For example, the command to modify the login shell of user

testuser to /bin/bash is as follows:

$ sudo usermod -s /bin/bash testuser

Step 3: Confirm User information modified successfully

After modifying the user information, you can use the following command to confirm that the user information has been modified successfully:

$ id <用户名>

Summary

Through the above steps, we can Modify user information below. Please note that when modifying user information, you need to execute commands with administrator privileges to ensure the security and correctness of the modification operation. Hope the above content is helpful to you.

The above is the detailed content of How to update user information in Linux system. 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