首页 > 解决方案 > 当我尝试 ssh 时如何解决“找不到匹配的 mac 错误”

问题描述

以下是我得到的错误:找不到匹配的mac:client hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96 server hmac-sha2 -512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,umac-128@openssh.com

标签: opensshhmacsha1

解决方案


在了解基础知识和根本原因之前,我已经为这个问题苦苦挣扎了很长时间。分享经验,以便它可以帮助某人。

我试图 ssh 到目标服务器并收到如下错误

$ ssh -A <someTargetServerNameOrIP>
Unable to negotiate with XX.XX.XX.XX port 1234: no matching MAC found.   
Their offer:   
hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,
umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,umac-128@openssh.com

此错误的根本原因是在您的源计算机上,支持的 MAC 不包含来自目标服务器的 MAC。

在您的机器上的命令行中查看此运行

$ ssh -Q mac   # output would be something like
hmac-sha1
hmac-sha1-96
hmac-sha2-256
hmac-sha2-512
hmac-md5
hmac-md5-96
umac-64@openssh.com
umac-128@openssh.com

因此,现在为了使用他们选择的服务器不支持的 mac 连接到目标服务器,您必须明确提供目标服务器支持的 mac 之一。例如,我们从错误消息中获取hmac-sha2-512并尝试连接,它将被连接

$ ssh -m hmac-sha2-512 -A <someTargetServerNameOrIP>

问题的另一个变体是密码不匹配,如下所示

$ ssh -A <someTargetServerNameOrIP>       
Unable to negotiate with XX.XX.XX.XX port 1234: no matching cipher found.   
Their offer: aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc

根本原因是密码不匹配

通过以下方式检查您支持的密码

$ ssh -Q cipher   # output would be something like
3des-cbc
aes256-cbc
rijndael-cbc@lysator.liu.se
aes128-ctr
aes192-ctr
aes256-ctr
aes128-gcm@openssh.com
aes256-gcm@openssh.com

因此,现在为了使用您的服务器不支持的密码选择连接到目标服务器,您必须明确提供目标服务器支持的密码之一。例如,我们从错误消息中获取 aes128-cbc 并尝试连接,它将被连接

$ ssh -c aes128-cbc -A <someTargetServerNameOrIP>

有关这方面的更多详细信息, 请参见https://diego.assencio.com/?index=688f3a536f63c43566c94f0818d9ecf3

希望这可以帮助某人。


推荐阅读