linux中集群的免秘鑰SSH直接登錄
阿新 • • 發佈:2019-05-08
主從服務器 完全 hostname 服務器 登錄 密碼登錄 5.4 ssh無密碼 無密碼登錄 這裏以三臺mysql的主從服務器為例:manage、master、slave1、slave2
給4個機器生成秘鑰文件
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory ‘/root/.ssh‘.
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
96:7e:3c:32:f2:44:e4:bc:79:6f:dd:b8:4e:46:17:37 [email protected]
The key‘s randomart image is:
+--[ RSA 2048]----+
| |
| |
| . E.|
| + . +|
| S . .|
|
+ + . . |
| . B = .oo |
| + = o.oo .|
| . ...o. |
+-----------------+ [[email protected] ~]# cd /root/
[[email protected] ~]# ll .ssh/
total 8
-rw-------. 1 root root 1675 Apr 28 10:24 id_rsa
-rw-r--r--. 1 root root 408 Apr 28 10:24 id_rsa.pub
[[email protected] ~]# cd .ssh/
[[email protected] .ssh]# ls
id_rsa id_rsa.pub
[[email protected] .ssh]# cp id_rsa.pub authorized_keys ####將id_rsa.pub公鑰拷貝重命名authorized_keys文件。 [[email protected] .ssh]# ls
authorized_keys id_rsa id_rsa.pub
[[email protected] ~]# ssh-copy-id -i manage_ip ###manage_ip是指manage這臺機器的Ip地址 [[email protected] ~]# ssh-copy-id -i manage_ip
將authorized_keys文件復制到其他機器
[[email protected] ~]# scp /root/.ssh/authorized_keys [email protected]_ip:/root/.ssh/authorized_keys [[email protected] ~]# scp /root/.ssh/authorized_keys [email protected]_ip:/root/.ssh/authorized_keys [[email protected] ~]# scp /root/.ssh/authorized_keys [email protected]_ip:/root/.ssh/authorized_keys 註意第一次ssh登錄時需要輸入密碼,再次訪問時即可免密碼登錄。
以manage為例,執行命令,生成空字符串的秘鑰(後面要使用公鑰),命令是:
[[email protected] ~]# ssh-keygen -t rsa -P ‘‘Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory ‘/root/.ssh‘.
Your identification has been saved in /root/.ssh/id_rsa.
The key fingerprint is:
96:7e:3c:32:f2:44:e4:bc:79:6f:dd:b8:4e:46:17:37 [email protected]
The key‘s randomart image is:
+--[ RSA 2048]----+
| |
| |
| . E.|
| + . +|
| S . .|
| . B = .oo |
| + = o.oo .|
| . ...o. |
+-----------------+ [[email protected] ~]# cd /root/
[[email protected] ~]# ll .ssh/
total 8
-rw-------. 1 root root 1675 Apr 28 10:24 id_rsa
-rw-r--r--. 1 root root 408 Apr 28 10:24 id_rsa.pub
[[email protected] ~]# cd .ssh/
id_rsa id_rsa.pub
[[email protected] .ssh]# cp id_rsa.pub authorized_keys ####將id_rsa.pub公鑰拷貝重命名authorized_keys文件。 [[email protected] .ssh]# ls
authorized_keys id_rsa id_rsa.pub
使用同樣的方法為master、slave1和slave2生成秘鑰(命令完全相同,不用做如何修改):
[[email protected] ~]# ssh-keygen -t rsa -P ‘‘ [[email protected] ~]# ssh-keygen -t rsa -P ‘‘ [[email protected] ~]# ssh-keygen -t rsa -P ‘‘ #登錄master、slave1、slave2,將公鑰拷貝到manage的authorized_keys中[[email protected] ~]# ssh-copy-id -i manage_ip ###manage_ip是指manage這臺機器的Ip地址 [[email protected] ~]# ssh-copy-id -i manage_ip
授權authorized_keys文件
登錄manage,在.ssh目錄下輸入命令:
[[email protected] ~]# cd /root/.ssh/ [[email protected] ~]# chmod 600 authorized_keys將authorized_keys文件復制到其他機器
[[email protected] ~]# scp /root/.ssh/authorized_keys [email protected]_ip:/root/.ssh/authorized_keys [[email protected] ~]# scp /root/.ssh/authorized_keys [email protected]_ip:/root/.ssh/authorized_keys [[email protected] ~]# scp /root/.ssh/authorized_keys [email protected]_ip:/root/.ssh/authorized_keys 註意第一次ssh登錄時需要輸入密碼,再次訪問時即可免密碼登錄。
測試連接成功的情況:
在manage機器上機器上運行:
配置SSH無密碼登錄認證
各節點生成秘鑰,並將公鑰傳送到其他服務器,包括自身,如在10.211.55.41創建秘鑰。
創建秘鑰
ssh-keygen -t rsa ###一直回車到結束即可
傳送到其他機器生成認證文件 ###然後分別在42-43-44機器上操作生成秘鑰分發各機器
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
linux中集群的免秘鑰SSH直接登錄