批量修改linux密码


以下为转载。
http://kerry.blog.51cto.com/172631/430745
[color=red][/color]

[root@manage .ssh]# cat ip_list.txt
192.168.9.201
192.168.9.202
如果远程服务器修改了默认ssh的端口号,就使用ssh -p 17173,17173为端口号

#!/bin/bash
#============== Though ssh remote server ,auto modify ROOT passwd =============#
for IP in `cat /root/ip_list.txt` #导入远程要修改主机的IP
do
#========================= 创建远程主机密码 ==========================#
TMP_PWD=`mkpasswd -l 8 -C 3`
R_PWD=`echo ${IP}_${TMP_PWD}`
echo "${IP}_${TMP_PWD}" > R_PWD.txt

#=========================== 修改远程主机密码 ========================#
if [ $? = 0 ] ; then
   ssh $IP passwd root --stdin < R_PWD.txt
   echo -e "$(date "+%Y-%m-%d %H:%M:%S")\t${IP}\t${R_PWD}\t" >> R_Server.log
else
   echo -e "$(date "+%Y-%m-%d %H:%M:%S")\t${IP} R_PWD.txt is create fail\tplease check!\t" >> M_pass.log
fi
if [ $? = 0 ] ; then
   echo -e "$(date "+%Y-%m-%d %H:%M:%S")\tThe ${IP} passwd is modify OK\t" >> M_pass.log
else
   echo -e "$(date "+%Y-%m-%d %H:%M:%S")\tThe ${IP} passwd is modify fail\tplease check!\t" >> M_pass.log
fi
done

你可能感兴趣的:(linux)