usermod命令
[root@lizhipeng01 ~]# id lizhipeng
uid=1000(lizhipeng) gid=1000(lizhipeng) groups=1000(lizhipeng)
[root@lizhipeng01 ~]# usermod -G grp2 lizhipeng 增加grp2为lizhipeng用户的扩展组
[root@lizhipeng01 ~]# id lizhipeng
uid=1000(lizhipeng) gid=1000(lizhipeng) groups=1000(lizhipeng),1005(grp2) 1005(grp2)扩展组
[root@lizhipeng01 ~]# usermod -G user2 lizhipeng
[root@lizhipeng01 ~]# id lizhipeng
uid=1000(lizhipeng) gid=1000(lizhipeng) groups=1000(lizhipeng),1006(user2) 替换了,原来的1005(grp2)没有了,变成了1006(user2)
[root@lizhipeng01 ~]# usermod -G grp2,user2 lizhipeng 同时指定grp2,user2
[root@lizhipeng01 ~]# id lizhipeng
uid=1000(lizhipeng) gid=1000(lizhipeng) groups=1000(lizhipeng),1005(grp2),1006(user2)
[root@lizhipeng01 ~]# usermod -g grp2,user2 lizhipeng
usermod: group ‘grp2,user2‘ does not exist
passwd命令
[root@lizhipeng01 ~]# passwd -l user5
锁定用户 user5 的密码 。
passwd: 操作成功
[root@lizhipeng01 ~]# tail /etc/shadow
tss:!!:17496::::::
postfix:!!:17496::::::
sshd:!!:17496::::::
lizhipeng:$6$HgNkSOb.$qZWdoTmwkhahlLiyyBwdMCYHVCmiKJ8MzSKK2cNd1H32P40.SFdMKdIDccQTJQLeJvzIMARpI81Z4Yqo6q3gv.:17503:0:99999:7:::
user1:!!:17518:0:99999:7:::
lzp:$6$Mxp/ziIl$yR1E/qeUJtwIeXw6dw2waxTpEisWl/4NERVI6IROPFPI1jj4tzJU4TUlp4QTe8oIV1yzifVxZ8g5vS58Zg.d70:17523:0:99999:7:::
user2:!!:17523:0:99999:7:::
user3:!!:17523:0:99999:7:::
user4:!!:17523:0:99999:7:::
user5:!!:17523:0:99999:7:::
[root@lizhipeng01 ~]# passwd -l lizhipeng
锁定用户 lizhipeng 的密码 。
passwd: 操作成功
[root@lizhipeng01 ~]# tail /etc/shadow
tss:!!:17496::::::
postfix:!!:17496::::::
sshd:!!:17496::::::
lizhipeng:!!$6$HgNkSOb.$qZWdoTmwkhahlLiyyBwdMCYHVCmiKJ8MzSKK2cNd1H32P40.SFdMKdIDccQTJQLeJvzIMARpI81Z4Yqo6q3gv.:17503:0:99999:7::: 多了两个感叹号,表示被锁定(!开头就表示被锁定,无论是1个叹号还是2个)
user1:!!:17518:0:99999:7:::
lzp:$6$Mxp/ziIl$yR1E/qeUJtwIeXw6dw2waxTpEisWl/4NERVI6IROPFPI1jj4tzJU4TUlp4QTe8oIV1yzifVxZ8g5vS58Zg.d70:17523:0:99999:7:::
user2:!!:17523:0:99999:7:::
user3:!!:17523:0:99999:7:::
user4:!!:17523:0:99999:7:::
user5:!!:17523:0:99999:7:::
[root@lizhipeng01 ~]# passwd -u lizhipeng 解锁
解锁用户 lizhipeng 的密码。
passwd: 操作成功
[root@lizhipeng01 ~]# tail /etc/shadow
tss:!!:17496::::::
postfix:!!:17496::::::
sshd:!!:17496::::::
lizhipeng:$6$HgNkSOb.$qZWdoTmwkhahlLiyyBwdMCYHVCmiKJ8MzSKK2cNd1H32P40.SFdMKdIDccQTJQLeJvzIMARpI81Z4Yqo6q3gv.:17503:0:99999:7:::
user1:!!:17518:0:99999:7:::
lzp:$6$Mxp/ziIl$yR1E/qeUJtwIeXw6dw2waxTpEisWl/4NERVI6IROPFPI1jj4tzJU4TUlp4QTe8oIV1yzifVxZ8g5vS58Zg.d70:17523:0:99999:7:::
user2:!!:17523:0:99999:7:::
user3:!!:17523:0:99999:7:::
user4:!!:17523:0:99999:7:::
user5:!!:17523:0:99999:7:::
[root@lizhipeng01 ~]# usermod -L lizhipeng 锁定lizhipeng
[root@lizhipeng01 ~]# tail /etc/shadow
tss:!!:17496::::::
postfix:!!:17496::::::
sshd:!!:17496::::::
lizhipeng:!$6$HgNkSOb.$qZWdoTmwkhahlLiyyBwdMCYHVCmiKJ8MzSKK2cNd1H32P40.SFdMKdIDccQTJQLeJvzIMARpI81Z4Yqo6q3gv.:17503:0:99999:7::: 1个感叹号
[root@lizhipeng01 ~]# usermod -U lizhipeng 解锁
[root@lizhipeng01 ~]# tail /etc/shadow
tss:!!:17496::::::
postfix:!!:17496::::::
sshd:!!:17496::::::
lizhipeng:$6$HgNkSOb.$qZWdoTmwkhahlLiyyBwdMCYHVCmiKJ8MzSKK2cNd1H32P40.SFdMKdIDccQTJQLeJvzIMARpI81Z4Yqo6q3gv.:17503:0:99999:7::: 感叹号没有了
[root@lizhipeng01 ~]# passwd --stdin user5
更改用户 user5 的密码 。
123456
passwd:所有的身份验证令牌已经成功更新。
[root@lizhipeng01 ~]# echo "111222" |passwd --stdin user5
更改用户 user5 的密码 。
passwd:所有的身份验证令牌已经成功更新。
[root@lizhipeng01 ~]# echo -e "123\nsss"
123
sss
[root@lizhipeng01 ~]# echo "123\nsss"
123\nsss
[root@lizhipeng01 ~]# echo -e "123\tsss"
123 sss
[root@lizhipeng01 ~]# echo -e "1231111\n1231111" |passwd user5
更改用户 user5 的密码 。
新的 密码:无效的密码: 密码少于 8 个字符
重新输入新的 密码:passwd:所有的身份验证令牌已经成功更新。
mkpasswd命令 yum install -y expect
[root@lizhipeng01 ~]# mkpasswd -l 12 设置密码长度为12
hw1gH(z1sTfe
[root@lizhipeng01 ~]# mkpasswd -l 12 -s 3 设置密码长度为12,包含3个特殊符号
i{d72zEkd~]W
[root@lizhipeng01 ~]# mkpasswd -l 12 -s 0
8jRjeOhdeim5