1. 适用于CentOS, Ubuntu
2. 定义地址池
3. 生成的密码会追加到密码文件里
4. 需要执行脚本的主机与其余主机做了基于key的验证, 适合在ansible主机上运行该脚本
IP_LIST="
10.0.0.19
10.0.0.29
10.0.0.81
10.0.0.82
10.0.0.227
10.0.0.217
"
DATE=`date +%F_%T`
for i in ${IP_LIST}; do
{
NEW_PASSWD=`cat /dev/urandom | tr -dc [:alnum:] | head -c 8`
ssh ${i} "grep Ubuntu /etc/issue &> /dev/null"
if [ $? -eq 0 ]; then
ssh ${i} "echo root:${NEW_PASSWD} | chpasswd"
echo "${i}:${NEW_PASSWD}" >> /root/passwd_history_${DATE}.txt
else
ssh ${i} "echo ${NEW_PASSWD} | passwd --stdin root &> /dev/null"
echo "${i}:${NEW_PASSWD}" >> /root/passwd_history_${DATE}.txt
fi
}&
done
网友评论