Home >Operation and Maintenance >Linux Operation and Maintenance >How to update 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.
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
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
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 olduser3. Modify the user’s home directoryIf 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 testuser4. Modify the user login ShellIf 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 testuserStep 3: Confirm User information modified successfullyAfter modifying the user information, you can use the following command to confirm that the user information has been modified successfully:
$ id <用户名>SummaryThrough 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!