首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> Java 程式設計 >> Java 綜合教學

SSH 啟動報「Could not load host key」錯誤排查與修復

     編輯:Java 綜合教學

SSH 啟動報「Could not load host key」錯誤排查與修復

現象

[root@aefe8007a17d ~]# /usr/sbin/sshd
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Could not load host key: /etc/ssh/ssh_host_ed25519_key

服務雖顯示啟動成功,但客戶端無法連線。

原因分析

  1. sshd_config 定義了主機金鑰檔案路徑,但實際檔案不存在
  2. OpenSSH 正常安裝會自動生成主機金鑰,此處因未知原因未生成
  3. 或檔案存在但大小為 0

檢查現狀

[root@aefe8007a17d ~]# ll /etc/ssh/
total 252
-rw-r--r-- 1 root root 242153 Mar 21 22:18 moduli
-rw-r--r-- 1 root root 2208 Mar 21 22:18 ssh_config
-rw------- 1 root root 4361 Mar 21 22:18 sshd_config
# 缺少 ssh_host_*_key 與 .pub 檔案

重新生成主機金鑰

1. RSA 金鑰

[root@aefe8007a17d ~]# ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /etc/ssh/ssh_host_rsa_key.
Your public key has been saved in /etc/ssh/ssh_host_rsa_key.pub.
...

2. ECDSA 金鑰

[root@aefe8007a17d ~]# ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key

3. Ed25519 金鑰

[root@aefe8007a17d ~]# ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key

驗證生成結果

[root@aefe8007a17d ~]# ll /etc/ssh/
total 276
-rw-r--r-- 1 root root 242153 Mar 21 22:18 moduli
-rw-r--r-- 1 root root 2208 Mar 21 22:18 ssh_config
-rw------- 1 root root 227 May 22 16:48 ssh_host_ecdsa_key
-rw-r--r-- 1 root root 179 May 22 16:48 ssh_host_ecdsa_key.pub
-rw------- 1 root root 411 May 22 16:48 ssh_host_ed25519_key
-rw-r--r-- 1 root root 99 May 22 16:48 ssh_host_ed25519_key.pub
-rw------- 1 root root 1679 May 22 16:48 ssh_host_rsa_key
-rw-r--r-- 1 root root 399 May 22 16:48 ssh_host_rsa_key.pub
-rw------- 1 root root 4361 Mar 21 22:18 sshd_config

測試連線

[root@localhost ~]# ssh 172.17.0.2
The authenticity of host '172.17.0.2 (172.17.0.2)' can't be established.
ECDSA key fingerprint is 37:2a:69:46:c4:bd:92:b2:43:b4:cc:42:41:8e:12:2e.
Are you sure you want to continue connecting (yes/no)?

輸入 yes 即可正常連線,問題解決。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved