Reference: Usermod manpage
Usermod-Modify user account information modify a user accounts
usermod [Options] Username
Option (Options)
-a|--append # #把用户追加到某些组中, only used with the-G option
-c|--comment # #修改/etc/passwd file Fifth paragraph comment
-d|--home # #修改用户的家目录通常和-m option used together
-e|--expiredate # #指定用户帐号禁用的日期, Format yy-mm-dd
-f|--inactive # #用户密码过期多少天后采用就禁用该帐号, 0 means the account is disabled after the password has expired-1 means disable this
function, default value is-1
-g|--gid # #修改用户的gid, reorganization must exist
-g|--groups # #把用户追加到某些组中, use only with-a option
-l|--login # #修改用户的登录名称
-l|--lock # #锁定用户的密码
-m|--move-home # #修改用户的家目录通常和-D option with
-s|--shell # #修改用户的shell
-u|--uid # #修改用户的uid, the UID must be unique
-u|--unlock # #解锁用户的密码
Example (Examples):
1, new user test, password test, plus add root group
[Email protected] ~]# Useradd test
[Email protected] ~]# echo "Test" | passwd--stdin Test
Change the password for the user test.
PASSWD: All the authentication tokens have been successfully updated.
2, add test user to Newtest Group
# #多个组之间用空格隔开
[Email protected] ~]# Usermod-ag newtest test
[[email protected] ~]# ID test
uid=500 (test) gid=500 (test) group =500 (test), 501 (newtest)
3, modify the test user's home directory
[Email protected] ~]# Usermod-md/home/jameszhan test
4, modify user name Test>jameszhan
#usermod-L Jameszhan (new user name) test (original user name)
[Email protected] ~]# usermod-l Jameszhan test
5, lock User-L
[Email protected] ~]# usermod-l Jameszhan
6, unlocking the user-U
[Email protected] ~]# usermod-u Jameszhan
7, modify the user's shell
[Email protected] ~]# usermod-s/bin/sh Jameszhan
8, modify the UID of the user
[[email protected] ~]# usermod-u 502 Jameszhan (UID must be unique)
[[email protected] ~]# ID Jameszhan
uid=502 (Jameszhan) gid=500 (test) groups=500 (test), 501 (usertest)
9, modify the user's GID
[Email protected] ~]# GROUPADD-G 502 Test1
[Email protected] ~]# USERMOD-G 502 Jameszhan
[[email protected] ~]# ID Jameszhan
uid=502 (Jameszhan) gid=502 (test1) groups=502 (test1), 501 (usertest)
10, specify the account expiration date
[Email protected] ~]# usermod-e 2017-11-14 Jameszhan
11, specify the user account password expires 7 days after the account is disabled
[Email protected] ~]# usermod-f 7 Jameszhan
Note (caution):
Usermod is used to change the UserID, it must be confirmed that the user does not perform any program on the computer
[Email protected] ~]# tail-1/etc/passwd
Jameszhan:x:500:500::/home/jameszhan:/bin/bash
[Email protected] ~]# tail-1/etc/shadow
jameszhan:$6$vuybok4e$6h5449gk3qjjfnabu3zvwfge422poazhjwkybmyiisyyfnv3/w0rksnxqbjxjytvy/.xdse.h7uytzlofcajv/ : 17119:0:99999:7:::
User name: password: Last time password change: Minimum age: Maximum Age: Warning Time: Expiry time
Note:
Last password change: The number of days since January 1, 1970 to the time the password was last modified
Minimum period of use: the password can be changed in a few days (0 means it can be changed at any time)
Maximum lifespan: Passwords must be changed in a few days (99999 means never expire)
Warning Time: A few days before the password expires remind the user (default is one week)
: Password expires several days payback number is disabled
: expiry date: From January 1, 1970, number of days after the account expires
This article is from the "James Zhan Linux Advanced ops" blog, so be sure to keep this source http://jameszhan.blog.51cto.com/10980469/1872751
Linux Basic Article-usermod command detailed