1.前言
为了降低服务器被侵入的风险,大部分公司引入了跳板机,跳板机可以在各个机器之间跳转,而每次输入密码是很繁琐的,因此设置免密登录是很有必要的。
2.配置
| 机器ip | 机器用途 |
|---|---|
| 10.1.1.110 | 跳板机 |
| 10.1.1.1 | 目标机器 |
以下操作均在跳板机执行
生成rsa秘钥 ssh-keygen -t rsa
将秘钥复制到指定机器 ssh-copy-id root@10.1.1.1,此步需要输入目标机器id,成功提示如下:
[root@zhiaiyahong ~]# ssh-copy-id root@10.1.1.1
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@10.1.1.1's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@10.1.1.1'"
and check to make sure that only the key(s) you wanted were added.
直接ssh目标机器即可登录ssh 10.1.1.1
3.拓展
- 集群
只需要多次执行ssh-copy-id root@目标机器即可 - 机器间互相登录
| 机器ip | 机器用途 |
|---|---|
| 10.1.1.2 | 主机1 |
| 10.1.1.3 | 主机2 |
主机1操作
生成rsa秘钥 ssh-keygen -t rsa
将秘钥复制到指定机器 ssh-copy-id root@10.1.1.3
主机2操作
生成rsa秘钥 ssh-keygen -t rsa
将秘钥复制到指定机器 ssh-copy-id root@10.1.1.2
即都生成秘钥,并将秘钥推送给对方,即可实现相互登录
4.参考文章
本人在操作时未遇到问题,如遇到问题可查看此文章
centos7(3)之SSH配置方法以及集群机器之间SSH免密码登录







网友评论