#!/bin/bash
hosts="172.16.15.3 172.16.15.4" #不要包含本机IP地址;
#配置免密登陆:
#ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa -q
#生成公钥私钥:
#ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa -q -b 2048 -C "1339329314@qq.com"
#参数详解:
#-N '' 密码为空;
#-f id_rsa是指保存文件为~/.ssh/id_rsa和~/.ssh/id_rsa.pub;
#-q 静默模式,和unzip的-q参数一样的;
#-b 位数,可以指定1024这类的,默认是2048;
#-C comment 提供一个新注释
#取消首次远程登录的时候都得输入yes让.ssh/know_hosts记住主机;
#echo "StrictHostKeyChecking no" > ~/.ssh/config
#将本机Key拷贝到其他机器上
for i in $hosts
do
#ssh root@$i "ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa -q"
#ssh root@$i "echo "StrictHostKeyChecking no" > ~/.ssh/config"
ssh-copy-id "root@$i" #cat ~/.ssh/authorized_keys
ssh root@$i "chmod 700 /root/.ssh/authorized_keys"
done