配置主机互信:
$ ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ''
将节点主机信息添加到本地,防止提醒
for host in 192.168.200.{27..33};do
ssh-keyscan $host >>~/.ssh/known_hosts 2>/dev/null
done
# 主机互信
for host in 192.168.2.{30..32};do
ssh-keyscan $host >>~/.ssh/known_hosts 2>/dev/null
done
发放公钥
方法一
cd /root/.ssh/
for host in 192.168.2.{31..32};do scp ./* $host:/root/.ssh/;done
# 方法二
for host in 192.168.2.{31..32};do
sshpass -p'123' ssh-copy-id root@$host &>/dev/null
done
-o参数
ssh -o ConnectTimeout=3 -o ConnectionAttempts=5 -o PasswordAuthentication=no -o StrictHostKeyChecking=no $ip “command”
1 ConnectTimeout=3 连接时超时时间,3秒
2 ConnectionAttempts=5 连接失败后重试次数,5次
3 PasswordAuthentication=no 是否使用密码认证,(在遇到没做信任关系时非常有用,不然会卡在那里)
4 StrictHostKeyChecking=no 第一次登陆服务器时自动拉取key文件,(跟上面一样,并且在第一次ssh登陆时,自动应答yes)