由于低版本的OpenSSH使用了过时不安全的加密算法协议,通常OpenSSH在版本迭代更新时会弃用这些不安全的加密算法。 如果我们仍要继续使用旧版本的OpenSSH,可以根据实际情况,考虑屏蔽掉不安全的加密算法,以降低安全风险
查看Kexalgorithms-此举操作是确认客户端支持的kexalgorithms
[root@cntf1 ~]
diffie-hellman-group1-sha1
diffie-hellman-group14-sha1
diffie-hellman-group14-sha256
diffie-hellman-group16-sha512
diffie-hellman-group18-sha512
diffie-hellman-group-exchange-sha1
diffie-hellman-group-exchange-sha256
ecdh-sha2-nistp256
ecdh-sha2-nistp384
ecdh-sha2-nistp521
curve25519-sha256
curve25519-sha256@libssh.org
gss-gex-sha1-
gss-group1-sha1-
gss-group14-sha1-
查看服务端支持的kexalgorithms
[root@cntf1 ~ ]# sshd -T | grep -w kexalgorithms
kexalgorithms curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group -exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group -exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
修复方法
man sshd_config |grep -A 40 -w KexAlgorithms
echo "KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521" >> /etc/ss h/sshd_config
systemctl restart sshd
sshd -T | grep -w kexalgorithms
curve25519-sha256
curve25519-sha256@libssh.org
diffie-hellman-group1-sha1
diffie-hellman-group14-sha1
diffie-hellman-group-exchange-sha1
diffie-hellman-group-exchange-sha256
ecdh-sha2-nistp256
ecdh-sha2-nistp384
ecdh-sha2-nistp521
未禁用diffie-hellman算法之前,可用正常使用ssh连接登录
C: \Users\0 xxxd>ssh -v -oKexAlgorithms=diffie-hellman-group1-sha1 root@192.168 .182.131
OpenSSH_for_Windows_8.1 p1, LibreSSL 3.0 .2
debug1: Reading configuration data C:\\Users\\0 xxxd/.ssh/config
debug1: Reading configuration data __PROGRAMDATA__\\ssh/ssh_config
debug1: Connecting to 192.168 .182.131 [192.168 .182.131 ] port 22 .
debug1: Connection established.
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_rsa type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_rsa-cert type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_dsa type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_dsa-cert type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_ecdsa type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_ecdsa-cert type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_ed25519 type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_ed25519-cert type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_xmss type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0 -OpenSSH_for_Windows_8.1
debug1: Remote protocol version 2.0 , remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH_7.0 *,OpenSSH_7.1 *,OpenSSH_7.2 *,OpenSSH_7.3 *,OpenSSH_7.4 *,OpenSSH_7.5 *,OpenSSH_7.6 *,OpenSSH_7.7 * compat 0 x04000002
debug1: Authenticating to 192.168 .182.131 :22 as
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: diffie-hellman-group1-sha1
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key : ecdsa-sha2-nistp256 SHA256:ufqEJ867EJk+iK7/RGfpFof5dtNTax88bvkEGdQSxhc
debug1: read_passphrase: can
The authenticity of host
ECDSA key fingerprint is SHA256:ufqEJ867EJk+iK7/RGfpFof5dtNTax88bvkEGdQSxhc.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory
debug1: Will attempt key : C:\\Users\\0 xxxd/.ssh/id_rsa
debug1: Will attempt key : C:\\Users\\0 xxxd/.ssh/id_dsa
debug1: Will attempt key : C:\\Users\\0 xxxd/.ssh/id_ecdsa
debug1: Will attempt key : C:\\Users\\0 xxxd/.ssh/id_ed25519
debug1: Will attempt key : C:\\Users\\0 xxxd/.ssh/id_xmss
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256 ,rsa-sha2-512 >
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue : publickey,gssapi-keyex,gssapi-with -mic,password
debug1: Next authentication method: publickey
debug1: Trying private key : C:\\Users\\0 xxxd/.ssh/id_rsa
debug1: Trying private key : C:\\Users\\0 xxxd/.ssh/id_dsa
debug1: Trying private key : C:\\Users\\0 xxxd/.ssh/id_ecdsa
debug1: Trying private key : C:\\Users\\0 xxxd/.ssh/id_ed25519
debug1: Trying private key : C:\\Users\\0 xxxd/.ssh/id_xmss
debug1: Next authentication method: password
debug1: read_passphrase: can
root@192.168 .182.131
debug1: Authentication succeeded (password).
Authenticated to 192.168 .182.131 ([192.168 .182.131 ]:22 ).
debug1: channel 0 : new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: ENABLE_VIRTUAL_TERMINAL_INPUT is supported. Reading the VTSequence from console
debug1: ENABLE_VIRTUAL_TERMINAL_PROCESSING is supported. Console supports the ansi parsing
debug1: client_input_global_request: rtype hostkeys-00 @openssh.com want_reply 0
Last login: Fri Jun 10 18 :09 :28 2022 from 192.168 .182.1
禁用了diffie-hellman算法之后,带上被禁用的密钥算法登录,显示不能正常使用ssh登录
C: \Users\0 xxxd>ssh -v -oKexAlgorithms=diffie-hellman-group1-sha1 root@192.168 .182.131
OpenSSH_for_Windows_8.1 p1, LibreSSL 3.0 .2
debug1: Reading configuration data C:\\Users\\0 xxxd/.ssh/config
debug1: Reading configuration data __PROGRAMDATA__\\ssh/ssh_config
debug1: Connecting to 192.168 .182.131 [192.168 .182.131 ] port 22 .
debug1: Connection established.
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_rsa type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_rsa-cert type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_dsa type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_dsa-cert type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_ecdsa type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_ecdsa-cert type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_ed25519 type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_ed25519-cert type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_xmss type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0 -OpenSSH_for_Windows_8.1
debug1: Remote protocol version 2.0 , remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH_7.0 *,OpenSSH_7.1 *,OpenSSH_7.2 *,OpenSSH_7.3 *,OpenSSH_7.4 *,OpenSSH_7.5 *,OpenSSH_7.6 *,OpenSSH_7.7 * compat 0 x04000002
debug1: Authenticating to 192.168 .182.131 :22 as
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: (no match)
Unable to negotiate with 192.168 .182.131 port 22 : no matching key exchange method found. Their offer: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
上述使用了禁用的加密算法进行ssh登录发现显示没有匹配到算法,然后无法正常登录
下面是直接正常ssh登录,不带任何加密算法,发现是可用正常使用ssh登录
C: \Users\0 xxxd>ssh -v root@192.168 .182.131
OpenSSH_for_Windows_8.1 p1, LibreSSL 3.0 .2
debug1: Reading configuration data C:\\Users\\0 xxxd/.ssh/config
debug1: Reading configuration data __PROGRAMDATA__\\ssh/ssh_config
debug1: Connecting to 192.168 .182.131 [192.168 .182.131 ] port 22 .
debug1: Connection established.
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_rsa type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_rsa-cert type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_dsa type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_dsa-cert type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_ecdsa type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_ecdsa-cert type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_ed25519 type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_ed25519-cert type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_xmss type -1
debug1: identity file C:\\Users\\0 xxxd/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0 -OpenSSH_for_Windows_8.1
debug1: Remote protocol version 2.0 , remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH_7.0 *,OpenSSH_7.1 *,OpenSSH_7.2 *,OpenSSH_7.3 *,OpenSSH_7.4 *,OpenSSH_7.5 *,OpenSSH_7.6 *,OpenSSH_7.7 * compat 0 x04000002
debug1: Authenticating to 192.168 .182.131 :22 as
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key : ecdsa-sha2-nistp256 SHA256:ufqEJ867EJk+iK7/RGfpFof5dtNTax88bvkEGdQSxhc
debug1: Host
debug1: Found key in C:\\Users\\0 xxxd/.ssh/known_hosts:9
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory
debug1: Will attempt key : C:\\Users\\0 xxxd/.ssh/id_rsa
debug1: Will attempt key : C:\\Users\\0 xxxd/.ssh/id_dsa
debug1: Will attempt key : C:\\Users\\0 xxxd/.ssh/id_ecdsa
debug1: Will attempt key : C:\\Users\\0 xxxd/.ssh/id_ed25519
debug1: Will attempt key : C:\\Users\\0 xxxd/.ssh/id_xmss
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256 ,rsa-sha2-512 >
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue : publickey,gssapi-keyex,gssapi-with -mic,password
debug1: Next authentication method: publickey
debug1: Trying private key : C:\\Users\\0 xxxd/.ssh/id_rsa
debug1: Trying private key : C:\\Users\\0 xxxd/.ssh/id_dsa
debug1: Trying private key : C:\\Users\\0 xxxd/.ssh/id_ecdsa
debug1: Trying private key : C:\\Users\\0 xxxd/.ssh/id_ed25519
debug1: Trying private key : C:\\Users\\0 xxxd/.ssh/id_xmss
debug1: Next authentication method: password
debug1: read_passphrase: can
root@192.168 .182.131
debug1: Authentication succeeded (password).
Authenticated to 192.168 .182.131 ([192.168 .182.131 ]:22 ).
debug1: channel 0 : new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: ENABLE_VIRTUAL_TERMINAL_INPUT is supported. Reading the VTSequence from console
debug1: ENABLE_VIRTUAL_TERMINAL_PROCESSING is supported. Console supports the ansi parsing
debug1: client_input_global_request: rtype hostkeys-00 @openssh.com want_reply 0
Last login: Fri Jun 10 18 :18 :17 2022 from 192.168 .182.1
参考
https://blog.csdn.net/zhongxj183/article/details/124928794
https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable/
https://www.openssh.com/security.html
https://blog.csdn.net/weixin_43767602/article/details/124793901
https://github.com/Balasys/dheater
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步