一-创建公私钥
ssh-keygen
# ls /root/.ssh
authorized_keys id_rsa id_rsa.pub
cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys
二-Are you sure you want to continue connecting (yes/no)?
避免提示输入yes/no
修改vim /etc/ssh/ssh_config
# StrictHostKeyChecking ask ====>改为
StrictHostKeyChecking no
三-expect实现SSH登录的自动交互
1.安装expect工具
yum -y install expect //安装expect
2.创建脚本
# cat sshkey.sh#!/bin/bash
#$1== ip
expect <<EE
spawn ssh $1 rm -rf /root/.ssh
expect "password" {send "123456\r"}
spawn ssh $1 mkdir /root/.ssh
expect "password" {send "123456\r"}
spawn scp /root/.ssh/authorized_keys $1:/root/.ssh/authorized_keys
expect "password" {send "123456\r"}
spawn scp /root/.ssh/id_rsa $1:/root/.ssh/id_rsa
expect "password" {send "123456\r"}
spawn scp /root/.ssh/id_rsa.pub $1:/root/.ssh/id_rsa.pub
expect "password" {send "123456\r"}
expect "#" {send "exit\r"}
EE
四-上传密钥
# for i in 192.168.4.{1..9};do bash sshkey.sh $i;done