ssh-keyscan 未显示 DSA ssh-dss 密钥

ssh-keyscan 未显示 DSA ssh-dss 密钥

我正在使用 ssh-keyscan 获取几个 SSH 服务器的公钥。我的其中一台设备仅支持 DSA / ssh-dss。带有“-t dsa”选项的 ssh-keyscan 无法获取公钥,而 Nmap 脚本 ssh-hostkey 实际上可以获取它。

ssh-密钥扫描:

weberjoh@nb15-lx:~$ ssh-keyscan -t dsa ssg-mgmt
# ssg-mgmt:22 SSH-2.0-NetScreen

Nmap:

weberjoh@nb15-lx:~$ nmap --script ssh-hostkey ssg-mgmt

Starting Nmap 7.01 ( https://nmap.org ) at 2017-10-11 16:00 CEST
Nmap scan report for ssg-mgmt (192.168.120.3)
Host is up (0.0026s latency).
rDNS record for 192.168.120.3: ssg-mgmt.webernetz.net
Not shown: 998 filtered ports
PORT    STATE SERVICE
22/tcp  open  ssh
| ssh-hostkey:
|_  1024 e7:5b:c9:a9:60:60:66:37:d6:90:bd:70:8f:76:e5:41 (DSA)
443/tcp open  https

Nmap done: 1 IP address (1 host up) scanned in 7.28 seconds

如何使用 ssh-keyscan 显示 DSA 公钥?

答案1

这可能是由于 OpenSSH 的新版本默认不支持DSA。在您的客户端计算机上,尝试在您的中添加以下内容~/.ssh/config

PubkeyAcceptedKeyTypes=+ssh-dss

还请记住,DSA 密钥可能不太安全,因此您应该考虑在您的服务器上替换它们(如果可能)。

答案2

这是解决 ssh-keyscan 不遵守 ~/.ssh/config 也不采取任何选项的解决方法。

$ ssh -o UserKnownHostsFile=junk -o KexAlgorithms=+diffie-hellman-group1-sha1 192.168.1.2
The authenticity of host '192.168.1.2 (192.168.1.2)' can't be established.
RSA key fingerprint is SHA256:iCnx+DQCcb4rAfNEE71mDiFc+ej9X+XBzBd/5/ueDtE.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.2' (RSA) to the list of known hosts.
root@router:~# ^D
Connection to 192.168.1.2 closed.
$ cut -d' ' -f2- < junk > junk2
$ ssh-keygen -r 192.168.1.2 -f junk2
192.168.1.2 IN SSHFP 1 1 28.....17
192.168.1.2 IN SSHFP 1 2 882....ed1
$ rm -f junk junk2

ssh -o UserKnownHostsFile=junk -o KexAlgorithms=+diffie-hellman-group1-sha1 -o HostKeyAlgorithms=ssh-dss 192.168.1.2

如果您想强制使用 DSA 而不是 RSA。

对于我们当中的懒人来说:

h=192.168.1.2; for t in ssh-rsa ssh-dss ssh-ed25519 ecdsa-sha2-nistp256 ecdsa-sha2-nistp384 ecdsa-sha2-nistp521; do ssh -o CheckHostIp=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=junk -o KexAlgorithms=+diffie-hellman-group1-sha1 -o HostKeyAlgorithms="${t}" "${h}" true && cut -d' ' -f2- < junk > junk2 && ssh-keygen -r "${h}" -f junk2; rm -f junk junk2; done

生成结果:

Warning: Permanently added '192.168.1.2' (RSA) to the list of known hosts.
192.168.1.2 IN SSHFP 1 1 28...17
192.168.1.2 IN SSHFP 1 2 882...ed1
Warning: Permanently added '192.168.1.2' (DSA) to the list of known hosts.
192.168.1.2 IN SSHFP 2 1 40..3c
192.168.1.2 IN SSHFP 2 2 26f...e6f
Unable to negotiate with 192.168.1.2 port 22: no matching host key type found. Their offer: ssh-rsa,ssh-dss
...

相关内容