[root@localhost /]# id hanfeng 这个组不只包括了前面的gid,还能够包括其余的扩展组 uid=1000(hanfeng) gid=1000(hanfeng) 组=1000(hanfeng) [root@localhost /]# groupadd ha1 [root@localhost /]# usermod -G ha1 hanfeng [root@localhost /]# id hanfeng uid=1000(hanfeng) gid=1000(hanfeng) 组=1000(hanfeng),1001(ha1) [root@localhost /]# useradd user3 [root@localhost /]# usermod -G user3 hanfeng [root@localhost /]# id hanfeng 这里会发现指定-G以后,user3组替代了ha1组 uid=1000(hanfeng) gid=1000(hanfeng) 组=1000(hanfeng),1002(user3) [root@localhost /]# usermod -G ha1,user3 hanfeng 同时添加多个组 [root@localhost /]# id hanfeng uid=1000(hanfeng) gid=1000(hanfeng) 组=1000(hanfeng),1001(ha1),1002(user3)
一个用户,它能够属于多个组,可是这个gid只有一个,咱们就能够把除了gid以外的组,称之为扩展组
[root@localhost /]# usermod -g ha1,user3 hanfeng usermod:“ha1,user3”组不存在 [root@localhost /]# usermod -g ha1 hanfeng [root@localhost /]# !id id hanfeng uid=1000(hanfeng) gid=1001(ha1) 组=1001(ha1),1002(user3)
--g与-G的区别,-g只能只能指定一个组,而-G能够指定多个组shell
[root@localhost /]# passwd 这里直接就可更改root用户的密码 更改用户 root 的密码 。 新的 密码: [root@localhost /]# passwd user3 在命令后面加上普通用户,便可更改密码 更改用户 user3 的密码 。 新的 密码: 从新输入新的 密码: passwd:全部的身份验证令牌已经成功更新。 [root@localhost /]# tail /etc/shadow 会看到user3这个多了一串加密的字符串 systemd-bus-proxy:!!:17459:::::: systemd-network:!!:17459:::::: dbus:!!:17459:::::: polkitd:!!:17459:::::: tss:!!:17459:::::: postfix:!!:17459:::::: sshd:!!:17459:::::: chrony:!!:17459:::::: hanfeng:!!:17470:0:99999:7::: user3:$6$1WEfFti.$gyRBbtnDqmAnsHDST5hIsE1oTlNhBAvasK3CTvCHIE2Bnga.mOZ7LWPR3xbfRz4vAtOlO6Z01iA47.evT90Nk0:17470:0:99999:7:::
[root@localhost ~]# head /etc/shadow root:$6$L6sm5Qq1aGOBJOIi$okCMP5JFEiDBpcaqreOtF54FA5.qyUTG/WfAj45Od7ONdM1Ut9buK9i4xdOcaBwUaX4x3oGd/wSJl4OWh0xOJ/::0:99999:7::: bin:*:17110:0:99999:7::: daemon:*:17110:0:99999:7::: adm:*:17110:0:99999:7::: lp:*:17110:0:99999:7::: sync:*:17110:0:99999:7::: shutdown:*:17110:0:99999:7::: halt:*:17110:0:99999:7::: mail:*:17110:0:99999:7::: operator:*:17110:0:99999:7:::
[root@hf-01 ~]# passwd -l hanfeng 会发现user10用户的密码被锁定了 锁定用户 hanfeng 的密码 。 passwd: 操做成功 [root@hf-01 ~]# tail -n7 /etc/shadow hanfeng:!!$6$jV74kWmS$GPP5amnrGjHQuAxqAAxyKHmLp6lOXd64pWl1YxVu5VfJSSJPFk4DvLhWhYM1.BfmXA32leqCMLcJYPeCmdBK/.:17469:0:99999:7::: user1:!!:17465:0:99999:7::: haha:!!:17469:0:99999:7::: user2:!!:17469:0:99999:7::: user4:!!:17469:0:99999:7::: user8:!!:17469:0:99999:7::: user10:!!:17469:0:99999:7:::
在密码文件的/etc/shadow中,会发现hanfeng用户的密码加上两个叹号!!。说明它被锁定了
[root@hf-01 ~]# passwd -u hanfeng 解锁用户 hanfeng 的密码。 passwd: 操做成功 [root@hf-01 ~]# tail -n7 /etc/shadow hanfeng:$6$jV74kWmS$GPP5amnrGjHQuAxqAAxyKHmLp6lOXd64pWl1YxVu5VfJSSJPFk4DvLhWhYM1.BfmXA32leqCMLcJYPeCmdBK/.:17469:0:99999:7::: user1:!!:17465:0:99999:7::: haha:!!:17469:0:99999:7::: user2:!!:17469:0:99999:7::: user4:!!:17469:0:99999:7::: user8:!!:17469:0:99999:7::: user10:!!:17469:0:99999:7:::
在/etc/shadow的密码文件中,会发现hanfeng用户下的两个叹号 !! 消失了,说明该用户解锁成功。
[root@hf-01 ~]# usermod -L hanfeng [root@hf-01 ~]# !tail tail -n7 /etc/shadow hanfeng:!$6$jV74kWmS$GPP5amnrGjHQuAxqAAxyKHmLp6lOXd64pWl1YxVu5VfJSSJPFk4DvLhWhYM1.BfmXA32leqCMLcJYPeCmdBK/.:17469:0:99999:7::: user1:!!:17465:0:99999:7::: haha:!!:17469:0:99999:7::: user2:!!:17469:0:99999:7::: user4:!!:17469:0:99999:7::: user8:!!:17469:0:99999:7::: user10:!!:17469:0:99999:7:::
在/etc/shadow密码文件中,会发现密码位置出现了一个叹号 ! ,无论是出现一个叹号,仍是两个叹号,只要是叹号开头了,就表示该用户被锁定了,不能登陆了。
[root@hf-01 ~]# usermod -U hanfeng [root@hf-01 ~]# !tail tail -n7 /etc/shadow hanfeng:$6$jV74kWmS$GPP5amnrGjHQuAxqAAxyKHmLp6lOXd64pWl1YxVu5VfJSSJPFk4DvLhWhYM1.BfmXA32leqCMLcJYPeCmdBK/.:17469:0:99999:7::: user1:!!:17465:0:99999:7::: haha:!!:17469:0:99999:7::: user2:!!:17469:0:99999:7::: user4:!!:17469:0:99999:7::: user8:!!:17469:0:99999:7::: user10:!!:17469:0:99999:7:::
[root@hf-01 ~]# passwd --stdin user10 更改用户 user10 的密码 。 hanfeng passwd:全部的身份验证令牌已经成功更新。 [root@hf-01 ~]# echo "123123" |passwd --stdin user10 这会在shell中常常使用到 更改用户 user10 的密码 。 passwd:全部的身份验证令牌已经成功更新。
[root@hf-01 ~]# echo "123\nsss" 123\nsss [root@hf-01 ~]# echo -e "123\nsss" 123 sss [root@hf-01 ~]# echo -e "123\tsss" 123 sss
[root@hf-01 ~]# echo -e "123456\n123456" |passwd user10 更改用户 user10 的密码 。 新的 密码:无效的密码: 密码少于 8 个字符 从新输入新的 密码:passwd:全部的身份验证令牌已经成功更新。 [root@hf-01 ~]# passwd user10 更改用户 user10 的密码 。 新的 密码: 无效的密码: 密码少于 8 个字符 从新输入新的 密码: passwd:全部的身份验证令牌已经成功更新。
这里会发现echo -e "***\n***" |passwd username这里更改用户密码,会比passwd username更改用户密码要方便不少,只需一次就可更改为功
原则:密码超过十位数起,要包括数字、大小写字母、特殊符号,这样才能成为一个合格的密码(密码不能有规律性,不能有本身的姓名、电话等,不然会很容易被猜到)ssh
[root@hf-01 ~]# mkpasswd 它会随机生成一个大小写、数字、符号的字符串,长度是 九位 UgftrS^57
[root@hf-01 ~]# mkpasswd -l 12 生成了长度为12位的字符串 9ue}dxdor2MM
[root@hf-01 ~]# mkpasswd -l 12 -s 3 xx[jbMk<9'M9 [root@hf-01 ~]# mkpasswd -l 12 -s 0 bevtic7Fu7Kh
在写脚本中常常会用到mkpasswd命令,再生成后,还需记录到文本文档中去