#!/bin/bash # 批量复制ssh公钥 IPS=( 192.168.10.183 192.168.10.190 192.168.10.89 192.168.10.212 ) for ip in "${IPS[@]}"; do echo "Checking connectivity to $ip" if ! ping -c 1 -W 1 $ip &>/dev/null; then echo "$ip is unreachable, skipping..." continue fi echo "Copying SSH key to $ip" if ! sshpass -p 123456 ssh-copy-id -o StrictHostKeyChecking=no root@$ip 2>/dev/null; then echo "Failed to copy key to $ip" fi done