批量修改Linux系统密码
截取主机IP地址最后一位数、匹配一组定义好的自定义密码、使用chpasswd修改主机账户密码
截图主机IP
[root@web01 ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:0c:29:b1:16:ba brd ff:ff:ff:ff:ff:ff inet 192.168.31.210/24 brd 192.168.31.255 scope global noprefixroute ens160 valid_lft forever preferred_lft forever inet6 fe80::473e:f49:a714:1ca4/64 scope link noprefixroute valid_lft forever preferred_lft forever 3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default link/ether 02:42:c0:7a:e5:3f brd ff:ff:ff:ff:ff:ff inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 valid_lft forever preferred_lft forever 4: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:0c:29:b1:16:c4 brd ff:ff:ff:ff:ff:ff inet 192.168.31.115/24 brd 192.168.31.255 scope global noprefixroute dynamic ens192 valid_lft 57401sec preferred_lft 57401sec inet6 fe80::30aa:1cb4:f641:c73f/64 scope link noprefixroute valid_lft forever preferred_lft forever 5: ens224: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:0c:29:b1:16:ce brd ff:ff:ff:ff:ff:ff inet 192.168.31.114/24 brd 192.168.31.255 scope global noprefixroute dynamic ens224 valid_lft 54676sec preferred_lft 54676sec inet6 fe80::6dac:7783:8994:35ce/64 scope link noprefixroute valid_lft forever preferred_lft forever 6: nm-team: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000 link/ether 22:12:15:c8:40:51 brd ff:ff:ff:ff:ff:ff [root@web01 ~]# ip addr |grep 192.168 inet 192.168.31.210/24 brd 192.168.31.255 scope global noprefixroute ens160 inet 192.168.31.115/24 brd 192.168.31.255 scope global noprefixroute dynamic ens192 inet 192.168.31.114/24 brd 192.168.31.255 scope global noprefixroute dynamic ens224 [root@web01 ~]# ip addr |grep 192.168|grep -v dynamic inet 192.168.31.210/24 brd 192.168.31.255 scope global noprefixroute ens160 [root@web01 ~]# ip addr |grep 192.168|grep -v dynamic|awk '{print $2}' 192.168.31.210/24 [root@web01 ~]# ip addr |grep 192.168|grep -v dynamic|awk '{print $2}'|cut -d / -f 1 192.168.31.210 [root@web01 ~]# ip addr |grep 192.168|grep -v dynamic|awk '{print $2}'|cut -d / -f 1|grep -o .$ 0 [root@web01 ~]#
批量修改脚本
#!/bin/bash A='ip addr |grep 192.168|grep -v dynamic|awk '{print $2}'|cut -d / -f 1|grep -o .$' if [ $A = 0 ] pass_login='Yqllm@0)' pass_root='Gslcl@0)' elif [$A = 1] pass_login='Yqylm@1!' pass_root='Gsycl@1!' elif [$A = 2] pass_login='Yqelm@2@' pass_root='Gsecl@2@' elif [$A = 3] pass_login='Yqslm@3#' pass_root='Gsscl@3#' elif [$A = 4] pass_login='Yqslm@4$' pass_root='Gsscl@4$' elif [$A = 5] pass_login='Yqwlm@5%' pass_root='Gswcl@5%' elif [$A = 6] pass_login='Yqllm@6^' pass_root='Gslcl@6^' elif [$A = 7] pass_login='Yqqlm@7&' pass_root='Gsqcl@7&' elif [$A = 8] pass_login='Yqblm@8*' pass_root='Gsbcl@8*' elif [$A = 9] pass_login='Yqjlm@9(' pass_root='Gsjcl@9(' fi echo "root password is $pass_root" echo "login password is $pass_login" echo root:$pass_root|chpasswd echo login:$pass_root|chpasswd chage -l root chage -l login