Linux SSH無密碼公鑰認證

實現:A、B兩臺linux服務器,A可以直接ssh 服務器B

原理:公鑰加密,私鑰解密。將A的公鑰拷貝到B服務器,當A ssh遠程B時,B會通過A的公鑰加密,生成隨機數,併發送給A。A通過自己的私鑰進行解密。

步驟:1、

A、B服務器執行ssh-keygen命令生成相應的公鑰私鑰

[root@VCS_Goo1 ~]# ssh-keygen

Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
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:
27:a9:9b:d6:59:12:1a:82:89:f2:4e:6f:bb:5b:aa:2b root@VCS_Goo1

2、

A服務器:

[root@VCS_Goo1 ~]#scp /root/.ssh/id_rsa.pub B服務器ip:/root/.ssh

3、

B服務器:

[root@VCS_Goo2 ~]#cd /root/.ssh

 [root@VCS_Goo2  .ssh]#mv id_rsa.pub authorized.keys    //將A的公鑰改名 authorized.keys

4、驗證

在A服務器上通過ssh遠程B服務器,發現不用輸入B服務器的密碼也可以。

(PS:如果想實現B服務器無密碼遠程A服務器,方法類似)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章