SSH免密碼登錄

背景:兩臺電腦,ip分別爲:5, 10(簡稱)

目的:ip地址5服務器通過ssh遠程訪問10.無需輸入密碼

1、首先在5上生成密鑰對。

#cd /root/.ssh
#ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): (直接回車)
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:
06:96:6b:56:0c:33:a4:24:16:8c:06:35:9b:98:8b:e7 [email protected]

2、在root/.ssh目錄下生成密鑰對 id_rsa和id_rsa.pub

其中id_rsa是私鑰,id_rsa.pub是公鑰。

3、將公鑰直接copy到10的/root/.ssh目錄下

#scp id_rsa.pub root@192.168.1.10:/root/.ssh

4、將10機器上的id_rsa.pub改名爲authorized_keys

#cd /root/.ssh
#mv id_rsa.pub authorized_keys

或者(推薦用這個)

cat id_rsa.pub>>authorized_keys

5、密鑰設置成功。5ssh訪問10無需密碼成功

#ssh 192.168.1.10
發佈了43 篇原創文章 · 獲贊 93 · 訪問量 24萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章