設置ssh信任關係

    這裏假設主機A用來連接到主機B

 

1. 在主機A上執行如下命令來生成配對密鑰:
ssh-keygen -t rsa

顯示信息如下:
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:
45:13:ec:31:f9:3d:25:54:7b:5f:03:40:ba:e9:76:cd root@bindiry-ubuntu

按三次回車。

 

這個命令生成一個密鑰對:id_rsa(私鑰文件)和id_rsa.pub(公鑰文件)。默認被保存在~/.ssh/目錄下。

 

2.爲 ~/.ssh 目錄設置權限:
chmod -R 755 .ssh (chmod 755 ~/.ssh)

 

注意id_rsa文件的權限必須是600


將 .ssh 目錄中的 id_rsa.pub 文件複製到 主機B 的 ~/.ssh/ 目錄中,並改名爲 authorized_keys

【或者在主機B的~/.ssh/ 目錄中創建文件authorized_keys(如果已經存在直接編輯) ,並將主機A的~/.ssh/id_rsa.pub的內容(只有一行)添加到authorized_keys 】

 

至此信任關係建立完畢,主機A不用輸密碼即可用ssh,scp來連接主機B

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