一、情境
把主機之間都能遠端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.#print#rsa key finger :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-root attempt!0.1.250.166] failed - possible break-root attempt!. 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:39910210. root@bogon ~]
#4、登陸成功後,我們需要在主機b也做下以上3步,這樣就可以互相免密碼ssh登陸。 (如果有多台主機,每台主機都做下相同操作,以便日後管理)。
建議用其他使用者做ssh登陸的話,調整目錄檔案權限
設定authorized_keys權限
chmod 644 authorized_keys
以上是linux遠端登入ssh免密碼配置的方法是什麼的詳細內容。更多資訊請關注PHP中文網其他相關文章!