paramiko 不兼容的 ssh 对等点(没有可接受的 kex 算法)

发布于 2024-12-02 14:13:15 字数 2573 浏览 0 评论 0原文

尝试使用 paramiko 库通过 ssh 连接到 Cisco ACS 设备时出现以下错误。我在 python 中使用 paramiko 没有问题,我可以从命令行 ssh 到这个框,或者使用 putty 没有问题。我已打开调试并复制了此处的信息。如果您能帮助我,请告诉我。

import paramiko
import sys
import socket

try:
    paramiko.common.logging.basicConfig(level=paramiko.common.DEBUG)
    sshConnection = paramiko.SSHClient()
    sshConnection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    sshConnection.connect('server',username='username',password='password')
except paramiko.BadAuthenticationType:
    sys.stdout.write('Bad Password!\n')     
    sys.exit()
except paramiko.SSHException, sshFail:
    sys.stdout.write('Connection Failed!\n')
    sys.stdout.write('%s\n' % sshFail)
    sys.exit()
except socket.error, socketFail:
    sys.stdout.write('Failed to open socket\n')
    sys.stdout.write('%s\n' % socketFail)
    sys.exit()

并返回调试输出:

DEBUG:paramiko.transport:starting thread (client mode): 0x14511d0L
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_5.3)
DEBUG:paramiko.transport:kex algos:['diffie-hellman-group14-sha1'] server key:['ssh-rsa'] client encrypt:['aes256-cbc', 'aes128-cbc', '3des-cbc'] server encrypt:['aes256-cbc', 'aes128-cbc', '3des-cbc'] client mac:['hmac-sha1'] server mac:['hmac-sha1'] client compress:['none', '[email protected]'] server compress:['none', '[email protected]'] client lang:[''] server lang:[''] kex follows?False
ERROR:paramiko.transport:Exception: Incompatible ssh peer (no acceptable kex algorithm)
ERROR:paramiko.transport:Traceback (most recent call last):
ERROR:paramiko.transport:  File "build\bdist.win32\egg\paramiko\transport.py", line 1546, in run
ERROR:paramiko.transport:    self._handler_table[ptype](self, m)
ERROR:paramiko.transport:  File "build\bdist.win32\egg\paramiko\transport.py", line 1618, in _negotiate_keys
ERROR:paramiko.transport:    self._parse_kex_init(m)
ERROR:paramiko.transport:  File "build\bdist.win32\egg\paramiko\transport.py", line 1731, in _parse_kex_init
ERROR:paramiko.transport:    raise SSHException('Incompatible ssh peer (no acceptable kex algorithm)')
ERROR:paramiko.transport:SSHException: Incompatible ssh peer (no acceptable kex algorithm)
ERROR:paramiko.transport:
Connection Failed!
Incompatible ssh peer (no acceptable kex algorithm)

我已确保安装了最新版本的 pycrypto 和 paramiko。

I'm getting the following error when trying to ssh to a Cisco ACS device using the paramiko library. I've used paramiko in python without issue, and I can ssh to this box from the command line, or using putty without issue. I've turned on debugging and copied the info here. Please let me know if you can help me out.

import paramiko
import sys
import socket

try:
    paramiko.common.logging.basicConfig(level=paramiko.common.DEBUG)
    sshConnection = paramiko.SSHClient()
    sshConnection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    sshConnection.connect('server',username='username',password='password')
except paramiko.BadAuthenticationType:
    sys.stdout.write('Bad Password!\n')     
    sys.exit()
except paramiko.SSHException, sshFail:
    sys.stdout.write('Connection Failed!\n')
    sys.stdout.write('%s\n' % sshFail)
    sys.exit()
except socket.error, socketFail:
    sys.stdout.write('Failed to open socket\n')
    sys.stdout.write('%s\n' % socketFail)
    sys.exit()

and the debug output returned:

DEBUG:paramiko.transport:starting thread (client mode): 0x14511d0L
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_5.3)
DEBUG:paramiko.transport:kex algos:['diffie-hellman-group14-sha1'] server key:['ssh-rsa'] client encrypt:['aes256-cbc', 'aes128-cbc', '3des-cbc'] server encrypt:['aes256-cbc', 'aes128-cbc', '3des-cbc'] client mac:['hmac-sha1'] server mac:['hmac-sha1'] client compress:['none', '[email protected]'] server compress:['none', '[email protected]'] client lang:[''] server lang:[''] kex follows?False
ERROR:paramiko.transport:Exception: Incompatible ssh peer (no acceptable kex algorithm)
ERROR:paramiko.transport:Traceback (most recent call last):
ERROR:paramiko.transport:  File "build\bdist.win32\egg\paramiko\transport.py", line 1546, in run
ERROR:paramiko.transport:    self._handler_table[ptype](self, m)
ERROR:paramiko.transport:  File "build\bdist.win32\egg\paramiko\transport.py", line 1618, in _negotiate_keys
ERROR:paramiko.transport:    self._parse_kex_init(m)
ERROR:paramiko.transport:  File "build\bdist.win32\egg\paramiko\transport.py", line 1731, in _parse_kex_init
ERROR:paramiko.transport:    raise SSHException('Incompatible ssh peer (no acceptable kex algorithm)')
ERROR:paramiko.transport:SSHException: Incompatible ssh peer (no acceptable kex algorithm)
ERROR:paramiko.transport:
Connection Failed!
Incompatible ssh peer (no acceptable kex algorithm)

I've made sure I have the most recent versions of pycrypto and paramiko installed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

习惯成性 2024-12-09 14:13:15

我在服务器端使用 Debian 8 和 OpenSSH 时遇到了类似的问题。

作为快速修复,服务器端的以下 Cipher/MACs/KexAlgorithms 设置修复了该问题:

在 /etc/ssh/sshd_config 中:

Ciphers [email protected],[email protected],aes256-ctr,aes128-ctr
MACs [email protected],[email protected],[email protected],hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,hmac-sha1
KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1

不过...您应该从安全角度分析这些设置看法。我把它设置在实验室环境中,所以没有关心它。

也不确定是否可以通过这种方式修改 Cisco ACS

I was having similar issue with Debian 8 and OpenSSH on the server side.

As a quick fix, the following Cipher/MACs/KexAlgorithms settings on the server side fixes the issue:

In /etc/ssh/sshd_config:

Ciphers [email protected],[email protected],aes256-ctr,aes128-ctr
MACs [email protected],[email protected],[email protected],hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,hmac-sha1
KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1

Though... you should analyze those settings from the security point of view. I set it in lab env, so didn't take care about it.

Also not sure if you can modify it in this way for Cisco ACS

尤怨 2024-12-09 14:13:15

我升级了 paramiko 来解决问题:

 sudo pip install paramiko --upgrade

我更新的 paramiko 版本是:

paramiko==2.0.2

I upgraded the paramiko to fix the problem:

 sudo pip install paramiko --upgrade

My updated version of paramiko is:

paramiko==2.0.2

心欲静而疯不止 2024-12-09 14:13:15

尝试使用 paramiko ssh 到 Aruba 设备时出现以下错误:

paramiko.ssh_exception.SSHException:不兼容的 ssh 对等点(没有可接受的 kex 算法)

执行 paramiko 升级解决了此问题:

sudo pip install paramiko --upgrade

I was getting the following error when trying to ssh to an Aruba device using paramiko:

paramiko.ssh_exception.SSHException: Incompatible ssh peer (no acceptable kex algorithm)

Doing a paramiko upgrade resolved this issue:

sudo pip install paramiko --upgrade
记忆之渊 2024-12-09 14:13:15

如果其他人在使用 pip install paramiko --upgrade 升级后仍然遇到此问题,请确保您没有在系统范围内安装 paramiko,因为它将在 pip 之前加载,您可以使用 dpkg -l | 检查它grep paramiko,如果已安装,请将其删除并通过 pip 安装。

In case anyone else is still having this issue even after upgrading using pip install paramiko --upgrade , be sure you don't have paramiko installed system wide, because it will be loaded before the pip ones, you can check it with dpkg -l | grep paramiko, if it's installed remove it and install through pip.

对我来说,我升级了 paramiko 的版本并解决了问题。具体来说,我最初通过 Ubuntu 14.04 python-paramiko 软件包安装了 paramiko,并使用 pip 将其替换为最新版本(1.10 -> 1.16)。

For me, I upgraded the version of paramiko and it resolved things. Specifically, I originally installed paramiko via the Ubuntu 14.04 python-paramiko package and replaced it with the latest using pip (1.10 -> 1.16).

落叶缤纷 2024-12-09 14:13:15

该错误是在您的 paramiko 版本不支持使用您要连接的设备的密钥交换算法的情况下出现的。

ssh.connect('10.119.94.8', 22, username="user",password='passwor')
t = ssh.get_transport()
so = t.get_security_options()
so.kex
('diffie-hellman-group1-sha1', 'diffie-hellman-group-exchange-sha1')
so.ciphers
('aes128-ctr', 'aes256-ctr', 'aes128-cbc', 'blowfish-cbc', 'aes256-cbc', '3des-cbc', 'arcfour128', 'arcfour256')
paramiko.__version__
'1.10.1'

在 paramiko 日志中,您可以看到连接的密钥交换算法。

DEB paramiko.transport: starting thread (client mode): 0x11897150L
INF paramiko.transport: Connected (version 2.0, client OpenSSH_7.2)
DEB paramiko.transport: kex algos:['diffie-hellman-group14-sha1', 'ecdh-sha2-nistp256', 'ecdh-sha2-nistp384'] server key:['ssh-rsa'] client encrypt:['aes128-ctr', 'aes256-ctr'] server encrypt:['aes128-ctr', 'aes256-ctr'] client mac:['hmac-sha1'] server mac:['hmac-sha1'] client compress:['none', '[email protected]'] server compress:['none', '[email protected]'] client lang:[''] server lang:[''] kex follows?False
ERR paramiko.transport: Exception: Incompatible ssh peer (no acceptable kex algorithm)
ERR paramiko.transport: Traceback (most recent call last):
ERR paramiko.transport:     raise SSHException('Incompatible ssh peer (no acceptable kex algorithm)')
ERR paramiko.transport: SSHException: Incompatible ssh peer (no acceptable kex algorithm)

因此,我建议升级到最新的 paramiko 版本,例如 2018 年的 2.4.2。此版本支持 sha1 和 sha2 密钥交换算法。

>>> ssh.connect("hostdev",22,username="user",password="pass")
>>> transport1=ssh.get_transport()
>>> so=transport1.get_security_options()
>>> so.kex
('ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group-exchange-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1')
>>> 
>>> so.ciphers
('aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-cbc', 'aes192-cbc', 'aes256-cbc', 'blowfish-cbc', '3des-cbc')
>>> 
>>> print paramiko.__version__
2.4.2

That error is in a situation where your version of paramiko does not support the key exchange algorithms that is using the device you want to connect.

ssh.connect('10.119.94.8', 22, username="user",password='passwor')
t = ssh.get_transport()
so = t.get_security_options()
so.kex
('diffie-hellman-group1-sha1', 'diffie-hellman-group-exchange-sha1')
so.ciphers
('aes128-ctr', 'aes256-ctr', 'aes128-cbc', 'blowfish-cbc', 'aes256-cbc', '3des-cbc', 'arcfour128', 'arcfour256')
paramiko.__version__
'1.10.1'

In the paramiko logs you can see the key exchange algos of your connection.

DEB paramiko.transport: starting thread (client mode): 0x11897150L
INF paramiko.transport: Connected (version 2.0, client OpenSSH_7.2)
DEB paramiko.transport: kex algos:['diffie-hellman-group14-sha1', 'ecdh-sha2-nistp256', 'ecdh-sha2-nistp384'] server key:['ssh-rsa'] client encrypt:['aes128-ctr', 'aes256-ctr'] server encrypt:['aes128-ctr', 'aes256-ctr'] client mac:['hmac-sha1'] server mac:['hmac-sha1'] client compress:['none', '[email protected]'] server compress:['none', '[email protected]'] client lang:[''] server lang:[''] kex follows?False
ERR paramiko.transport: Exception: Incompatible ssh peer (no acceptable kex algorithm)
ERR paramiko.transport: Traceback (most recent call last):
ERR paramiko.transport:     raise SSHException('Incompatible ssh peer (no acceptable kex algorithm)')
ERR paramiko.transport: SSHException: Incompatible ssh peer (no acceptable kex algorithm)

So I recommend to upgrade to a recent paramiko version, for example 2.4.2 for 2018. In this version is supported sha1 and sha2 for key exchange algorithms.

>>> ssh.connect("hostdev",22,username="user",password="pass")
>>> transport1=ssh.get_transport()
>>> so=transport1.get_security_options()
>>> so.kex
('ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group-exchange-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1')
>>> 
>>> so.ciphers
('aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-cbc', 'aes192-cbc', 'aes256-cbc', 'blowfish-cbc', '3des-cbc')
>>> 
>>> print paramiko.__version__
2.4.2
国产ˉ祖宗 2024-12-09 14:13:15

这可能对OP的情况没有帮助,但希望它可以帮助其他有同样错误的人。

我遇到了一种情况,一个脚本可以很好地通过 SSH 连接到系统,但另一个类似的脚本会失败并出现相同的

paramiko.SSHException: Incompatible ssh peer (no acceptable kex algorithm)

错误。

事实证明,这种情况就像我剧本顶部的那句台词:

#!/usr/bin/python

会失败,但

#!/usr/bin/env python

会成功。

我在系统上使用 virtualenvs,因此失败的 /usr/bin/python 版本使用的是系统上安装的较旧的 Paramiko 版本,而 /usr/bin/env python< /code> 版本在我的 virtualenv 中使用较新的 Paramiko 安装。

This may not help the OP's situation, but hopefully it may help someone else with the same error.

I ran into a situation where one script would SSH into a system just fine, but another similar script would fail with the same

paramiko.SSHException: Incompatible ssh peer (no acceptable kex algorithm)

error.

The situation turned out to be the shebang line at the top of my script:

#!/usr/bin/python

Would fail, while

#!/usr/bin/env python

would succeed.

I'm using virtualenvs on my system, so the failing /usr/bin/python version was using the older Paramiko version installed on the system, whereas the /usr/bin/env python version was using the newer Paramiko installation in my virtualenv.

那一片橙海, 2024-12-09 14:13:15

我最近在将服务器从 Ubuntu 20 更新到 22 以及不同的 VPS 提供商时遇到了这个问题。手动 SSH 很好,没有任何改变,但 paramiko 破坏了我的脚本。

在本地,我的 python 3.8 venv 有:

paramiko 2.8.1

在通常的连接调用中:

from paramiko import SSHClient
client = SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(...

我收到:

paramiko.ssh_exception.SSHException:不兼容的 ssh 对等(没有可接受的主机密钥)

正如Romaan 早先所说的,我需要的是:

pip install --upgrade paramiko
...
Successfully installed paramiko-2.11.0

只是想说明一下他的回答对我的背景很有帮助,表明它仍然具有相关性。

I recently came across this as I updated my server from Ubuntu 20 to 22, and a different VPS provider. Manual SSH was fine, nothing had changed, but paramiko was breaking my scripts.

Locally, my python 3.8 venv had:

paramiko 2.8.1

At the usual call to connect:

from paramiko import SSHClient
client = SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(...

I received:

paramiko.ssh_exception.SSHException: Incompatible ssh peer (no acceptable host key)

As Romaan said much earlier all I needed was:

pip install --upgrade paramiko
...
Successfully installed paramiko-2.11.0

Just wanted to illustrate his helpful answer with my context to show it is still relevant.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文