共計 1824 個字符,預計需要花費 5 分鐘才能閱讀完成。
本篇內容主要講解“linux 遠程登錄 ssh 免密碼配置的方法是什么”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓丸趣 TV 小編來帶大家學習“linux 遠程登錄 ssh 免密碼配置的方法是什么”吧!
一、情景
把主機之間都能遠程 ssh 免密碼登陸。
二、原理
很簡單,使用 ssh-keygen 在主機 a 上生成 private 和 public 密鑰,將生成的 public 密鑰拷貝到遠程機器主機 b 上后, 就可以使用 ssh 命令無需密碼登錄到另外一臺機器主機 b 上。
三、步驟
主機 a:
1、生成公鑰和私鑰文件 id_rsa 和 id_rsa.pub(敲 3 下回車即可)
[root@bogon ~]# 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:
67:da:0d:79:e0:d6:2b:cd:7d:22:af:51:7e:9c:75:fe root@bogon
the key s randomart image is:
+–[rsa 2048]—-+
| |
| |
| . |
| . + |
| s b o . o|
| * * = o+|
| . o b +.=|
| . + +.|
| … e|
+—————–+
2、ssh-cop-id 命令會將指定的公鑰文件復制到遠程計算機
[root@bogon ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.1.250.166
the authenticity of host 10.1.250.166 (10.1.250.166) can t be established.
rsa key fingerprint is c8:9d:6d:92:55:77:3d:3e:af:f5:cb:18:80:5a:47:93.
are you sure you want to continue connecting (yes/no)? yes
warning: permanently added 10.1.250.166 (rsa) to the list of known hosts.
reverse mapping checking getaddrinfo for bogon [10.1.250.166] failed – possible break-in attempt!
root@10.1.250.166 s password: 主機 b 的登陸密碼
now try logging into the machine, with ssh root@10.1.250.166 , and check in:
.ssh/authorized_keys
to make sure we haven t added extra keys that you weren t expecting.
3、然后 ssh 登陸主機 b 驗證是否需要密碼
[root@localhost ~]# ssh 10.1.250.166
reverse mapping checking getaddrinfo for bogon [10.1.250.166] failed – possible break-in attempt!
last login: wed oct 21 10:05:39 2015 from 10.1.250.141
[root@bogon ~]#
4、登陸成功后,我們需要在主機 b 也做下以上 3 步,這樣就可以相互免密碼 ssh 登陸。(如果有多臺主機,每臺主機都做下相同操作,以方便以后管理)。
5、權限問題
建議用其他用戶做 ssh 登陸的話,調整目錄文件權限
設置 authorized_keys 權限
chmod 644 authorized_keys
設置.ssh 目錄權限
chmod 700 -r .ssh
6、要保證.ssh 和 authorized_keys 都只有用戶自己有寫權限。否則驗證無效。
到此,相信大家對“linux 遠程登錄 ssh 免密碼配置的方法是什么”有了更深的了解,不妨來實際操作一番吧!這里是丸趣 TV 網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!