命令介绍
命令:usermod 修改用户
用法:usermod [options] usermod 用户
命令选项
[root@fp-21 ~]# usermod --help
-c, --comment COMMENT # 修改用户的备注信息
-d, --home HOME_DIR # 修改用户的新家目录
-e, --expiredate EXPIRE_DATE # 修改帐号的有效期限
-f, --inactive INACTIVE # 修改在密码过期后多少天即关闭该帐号
-g, --gid GROUP # 修改用户所属的群组
-G, --groups GROUPS # 修改用户所属的附加群组
-a, --append # 将用户附加到-G选项提到的其他组,而不从其他组中删除它
-h, --help # 帮助文档
-l, --login NEW_LOGIN # 修改用户名
-L, --lock # 锁定用户密码,使密码失效
-m, --move-home # 将家目录移动到新位置(只与-d一块使用)
-o, --non-unique # 允许使用重复UID
-p, --password PASSWORD # 对新密码使用加密密码
-u, --uid UID # 修改用户的UID
-U, --unlock # 解锁用户账户
命令实例
# 修改用户的备注信息
[root@fp-21 ~]# grep "test01" /etc/passwd
test01:x:1001:1001:This is first user:/home/test01:/bin/bash
[root@fp-21 ~]# usermod -c "whis is modify user" test01
[root@fp-21 ~]# grep "test01" /etc/passwd
test01:x:1001:1001:whis is modify user:/home/test01:/bin/bash
# 将家目录移动到新位置(只与-d一块使用)
[root@fp-21 ~]# grep "test02" /etc/passwd
test02:x:1002:1002::/opt/test:/bin/bash
[root@fp-21 ~]# usermod -d /home/test02 -m test02
[root@fp-21 ~]# grep "test02" /etc/passwd
test02:x:1002:1002::/home/test02:/bin/bash
# 修改用户所属的群组
[root@fp-21 ~]# grep "test03" /etc/passwd
test03:x:1003:1003::/home/test03:/bin/bash
[root@fp-21 ~]# usermod -g test01 test03
[root@fp-21 ~]# grep "test03" /etc/passwd
test03:x:1003:1001::/home/test03:/bin/bash
# 修改用户的UID
[root@fp-21 ~]# grep "test05" /etc/passwd
test05:x:1005:1005::/home/test05:/bin/bash
[root@fp-21 ~]# usermod -u 777 test05
[root@fp-21 ~]# grep "test05" /etc/passwd
test05:x:777:1005::/home/test05:/bin/bash