usermod

Used to modify the user's basic information

Supplementary instructions

usermod command is used to modify the basic information of the user. The usermod command does not allow you to change the name of an online user account. When the usermod command is used to change the user ID, it must be confirmed that this user is not executing any programs on the computer. You need to manually change the user's crontab file. It is also necessary to manually change the user's at profile. To use NIS server, you need to change the relevant NIS settings on the server.

grammar

usermod(option)(parameter)

Options

-c<remark>: Modify the remark text of the user account;
-d <login directory>: Modify the directory when the user logs in. It only modifies the user's home directory configuration information in /etc/passwd. It will not automatically create a new home directory. It is usually used together with -m;
-m <Move user home directory>: Move the user's home directory to a new location. It cannot be used alone. It is generally used together with -d.
-e<validity period>: Modify the validity period of the account;
-f <buffer days>: Modify the number of days after the password expires before the account will be closed;
-g<group>: Modify the group to which the user belongs;
-G<group>; modify the additional groups to which the user belongs;
-l<Account name>: Modify the user account name;
-L: Lock the user password and invalidate the password;
-s<shell>: Modify the shell used by the user after logging in;
-u<uid>: Modify user ID;
-U: Unlock password.

Parameters

Login name: Specify the login name of the user whose information is to be modified.

Example

Add newuser2 to group staff:

usermod -G staff newuser2

Modify newuser’s username to newuser1:

usermod -l newuser1 newuser

Lock account newuser1:

usermod -L newuser1

Unlock newuser1:

usermod -U newuser1

Add users to user groups:

apk add shadow #Install shadow package, usermod command is included in usermod
usermod -aG group user #Add user to user group

The -a parameter means appending and is only used together with the -G parameter to add the user to the group.

Modify user home directory:

[root@node-1 ~]# useradd lutixiaya
[root@node-1 ~]# ls /home
lutixiaya
[root@node-1 ~]# usermod -md /data/new_home lutixiaya
[root@node-1 ~]# ls /home/
[root@node-1 ~]# ls /data/
new_home