SSH 免密-多主机

需求:

一台主机可以免密登陆多台不同的主机

解决

  1. 添加配置文件 ~/.ssh/config
# bi-web - 主机1
Host 192.168.1.38
HostName 192.168.1.38
Port 22
PreferredAuthentications publickey
IdentityFile ~/.ssh/bi_rsa

# 132 - 座位底下虚拟机 - 主机2
Host 192.168.1.132
HostName 192.168.1.132
Port 22
PreferredAuthentications publickey
IdentityFile ~/.ssh/132_rsa

问题:

ssh 192.168.1.132
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/root/.ssh/132_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/root/.ssh/132_rsa": bad permissions
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

解决:密钥权限设置不对,修改命令如下

[root@localhost .ssh]# chmod 0600 132_rsa
# 测试登陆
[root@localhost .ssh]# ssh 192.168.1.132
Last login: Tue Sep 3 10:20:02 2019 from 192.168.0.136