1.前言
為了降低服務(wù)器被侵入的風(fēng)險(xiǎn),大部分公司引入了跳板機(jī),跳板機(jī)可以在各個(gè)機(jī)器之間跳轉(zhuǎn),而每次輸入密碼是很繁瑣的,因此設(shè)置免密登錄是很有必要的。
2.配置
| 機(jī)器ip | 機(jī)器用途 |
|---|---|
| 10.1.1.110 | 跳板機(jī) |
| 10.1.1.1 | 目標(biāo)機(jī)器 |
以下操作均在跳板機(jī)執(zhí)行
生成rsa秘鑰 ssh-keygen -t rsa
將秘鑰復(fù)制到指定機(jī)器 ssh-copy-id root@10.1.1.1,此步需要輸入目標(biāo)機(jī)器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目標(biāo)機(jī)器即可登錄ssh 10.1.1.1
3.拓展
- 集群
只需要多次執(zhí)行ssh-copy-id root@目標(biāo)機(jī)器即可 - 機(jī)器間互相登錄
| 機(jī)器ip | 機(jī)器用途 |
|---|---|
| 10.1.1.2 | 主機(jī)1 |
| 10.1.1.3 | 主機(jī)2 |
主機(jī)1操作
生成rsa秘鑰 ssh-keygen -t rsa
將秘鑰復(fù)制到指定機(jī)器 ssh-copy-id root@10.1.1.3
主機(jī)2操作
生成rsa秘鑰 ssh-keygen -t rsa
將秘鑰復(fù)制到指定機(jī)器 ssh-copy-id root@10.1.1.2
即都生成秘鑰,并將秘鑰推送給對(duì)方,即可實(shí)現(xiàn)相互登錄
4.參考文章
本人在操作時(shí)未遇到問題,如遇到問題可查看此文章
centos7(3)之SSH配置方法以及集群機(jī)器之間SSH免密碼登錄