在尝试启动 ssh 服务器守护程序时,我收到有关缺少主机密钥的错误,但是,查看后/etc/ssh
发现主机密钥在那里,并且我相信权限是正确的。
这是嵌入式 Linux 系统上的 OpenSSH 8.3p1。
对我的 OpenSSH 配置有什么问题有什么想法吗?
~> ls -l /etc/ssh
total 529
-rw-r--r-- 1 root root 525809 Mar 30 15:16 moduli
-rw-r--r-- 1 root root 1484 Mar 30 15:16 ssh_config
-rw------- 1 root root 1369 Mar 30 19:02 ssh_host_dsa_key
-rw-r--r-- 1 root root 600 Mar 30 19:02 ssh_host_dsa_key.pub
-rw------- 1 root root 505 Mar 30 19:02 ssh_host_ecdsa_key
-rw-r--r-- 1 root root 172 Mar 30 19:02 ssh_host_ecdsa_key.pub
-rw------- 1 root root 399 Mar 30 19:02 ssh_host_ed25519_key
-rw-r--r-- 1 root root 92 Mar 30 19:02 ssh_host_ed25519_key.pub
-rw------- 1 root root 2590 Mar 30 19:02 ssh_host_rsa_key
-rw-r--r-- 1 root root 564 Mar 30 19:02 ssh_host_rsa_key.pub
-rw-r--r-- 1 root root 2333 Mar 30 17:29 sshd_config
~> systemctl status sshd
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2021-03-30 19:02:43 UTC; 8s ago
Process: 338 ExecStartPre=/usr/bin/ssh-keygen -A (code=exited, status=0/SUCCESS)
Process: 465 ExecStart=/usr/sbin/sshd -D -e (code=exited, status=1/FAILURE)
Main PID: 465 (code=exited, status=1/FAILURE)
Mar 30 19:02:41 cm1sd ssh-keygen[338]: ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519
Mar 30 19:02:41 cm1sd systemd[1]: Started OpenSSH server daemon.
Mar 30 19:02:43 cm1sd sshd[465]: sshd: no hostkeys available -- exiting.
Mar 30 19:02:43 cm1sd systemd[1]: sshd.service: Main process exited, code=exited, status=1/FAILURE
Mar 30 19:02:43 cm1sd systemd[1]: sshd.service: Failed with result 'exit-code'.
编辑:
该配置确实包含 HostKey
HostKey /etc/ssh/ssh_host_rsa_key
编辑2:
我已更新到 OpenSSH 8.5p1 并在启用调试的情况下运行并获取一些附加信息:
~> sshd -D -e -ddd
debug2: load_server_config: filename /etc/ssh/sshd_config
debug2: load_server_config: done config len = 374
debug2: parse_server_config_depth: config /etc/ssh/sshd_config len 374
debug3: /etc/ssh/sshd_config:14 setting Port 10505
debug3: /etc/ssh/sshd_config:19 setting HostKey /etc/ssh/ssh_host_rsa_key
debug3: /etc/ssh/sshd_config:35 setting MaxAuthTries 6
debug3: /etc/ssh/sshd_config:36 setting MaxSessions 2
debug3: /etc/ssh/sshd_config:38 setting PubkeyAuthentication yes
debug3: /etc/ssh/sshd_config:42 setting AuthorizedKeysFile .ssh/authorized_keys
debug3: /etc/ssh/sshd_config:55 setting IgnoreRhosts yes
debug3: /etc/ssh/sshd_config:58 setting PasswordAuthentication no
debug3: /etc/ssh/sshd_config:59 setting PermitEmptyPasswords no
debug3: /etc/ssh/sshd_config:67 setting X11Forwarding no
debug3: /etc/ssh/sshd_config:89 setting Subsystem sftp /usr/libexec/sftp-server
debug1: sshd version OpenSSH_8.5, OpenSSL 1.1.1k 25 Mar 2021
Unable to load host key "/etc/ssh/ssh_host_rsa_key": error in libcrypto
Unable to load host key: /etc/ssh/ssh_host_rsa_key
sshd: no hostkeys available -- exiting.
看起来问题出在 OpenSSL 的 libcrypto 上。我安装了 OpenSSL 版本 1.1.1k。
答案1
在 WSL 上,这有效:
sudo ssh-keygen -A
sudo service ssh --full-restart