一、添加主机列表
vi /etc/hosts
// 添加内容
ip1 hoatnmae1
ip2 hoatnmae2
ip3 hoatnmae3
二、秘钥分发
2.1、生成秘钥
ssh-keygen -t rsa
2.2、复制秘钥
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
2.3、分发秘钥
ssh-copy-id -i ~/.ssh/id_rsa.pub -p22 root@192.168.xx.xx
三、分发时报错
分发秘钥时报以下错误,一般是由于更改主机 ip 或主机名重新分发秘钥引起的!
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:HDjXJvu0VYXWF+SKMZjSGn4FQmg/+w6eV9ljJvIXpx0.
Please contact your system administrator.
Add correct host key in /Users/wangdong/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/wangdong/.ssh/known_hosts:46
ECDSA host key for 192.168.xx.xx has changed and you have requested strict checking.
Host key verification failed.
解决:
ssh-keygen -R 192.168.xx.xx