paramiko 不兼容的 ssh 对等方(无可接受的密钥交换算法)
我在尝试用paramiko库通过ssh连接到一个Cisco ACS设备时遇到了以下错误。我之前在Python中使用过paramiko,没有问题,而且我可以通过命令行或用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', 'zlib@openssh.com'] server compress:['none', 'zlib@openssh.com'] 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。
8 个回答
2
我在用paramiko连接一个Aruba设备时遇到了以下错误:
paramiko.ssh_exception.SSHException: 不兼容的ssh对等体(没有可接受的密钥交换算法)
通过升级paramiko解决了这个问题:
sudo pip install paramiko --upgrade
20
我升级了paramiko来解决这个问题:
sudo pip install paramiko --upgrade
我更新后的paramiko版本是:
paramiko==2.0.2
21
我在使用Debian 8和OpenSSH的服务器时遇到了类似的问题。
作为一个快速解决办法,可以在服务器上调整以下Cipher/MACs/KexAlgorithms的设置来解决这个问题:
在 /etc/ssh/sshd_config 文件中:
Ciphers aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes128-ctr
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com,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的设置。