1、密钥对制作
yum -y install sshpass
免交互创建密钥对
ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ""
ll .ssh/
2、密钥分发
ssh-copy-id -i ~/.ssh/id_rsa.pub -o StrictHostKeyChecking=no -p50022 zlsduser@10.1.3.$ip
免交互方式批量分发公钥
##!/bin/bash
## create key pair
#rm -fr /root/.ssh/id_dsa*
#ssh-keygen -t dsa -f /root/.ssh/id_dsa -P "" -q
# fenfa key file
for ip in 100 110
do
echo "=======Batch the file to the host 10.1.3.$ip=========="
sshpass -p50022 ssh-copy-id -i /root/.ssh/id_dsa.pub "-o StrictHostKeyChecking=no zlsduser@10.1.3.$ip"
echo -e "##########################END##########################\n"
done
3、配置文件权限
chmod 700 /home/用户名/.ssh
chmod 600 authorized_keys
A要免密连接B,A要把自己的公钥发送给B的authorized_keys里。