批量测试免密登录连通性
单笔测试:
ssh -o ConnectTimeout=3 -o PasswordAuthentication=no -o NumberOfPasswordPrompts=0 user@ip echo "ok" if [[ $? -ne 0 ]]; then echo "error" fi;
从ip.txt文件中读取ip(一行一个IP),进行批量测试
user=免密的用户名
while read ip do ssh -o ConnectTimeout=3 -o PasswordAuthentication=no -o NumberOfPasswordPrompts=0 $user@$ip echo "$ip ok" if [[ $? -ne 0 ]]; then echo "$ip error" fi; sleep 0.2 done < ip.txt