当尝试使用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('%sn' % sshFail)
sys.exit()
except socket.error, socketFail:
sys.stdout.write('Failed to open socketn')
sys.stdout.write('%sn' % 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 "buildbdist.win32eggparamikotransport.py", line 1546, in run
ERROR:paramiko.transport: self._handler_table[ptype](self, m)
ERROR:paramiko.transport: File "buildbdist.win32eggparamikotransport.py", line 1618, in _negotiate_keys
ERROR:paramiko.transport: self._parse_kex_init(m)
ERROR:paramiko.transport: File "buildbdist.win32eggparamikotransport.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。
我在服务器端使用Debian 8和OpenSSH时也遇到了类似的问题。
作为快速修复,服务器端的以下Cipher/mac/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
我升级了paramiko来解决这个问题:
sudo pip install paramiko --upgrade
我的paramiko更新版本是:
paramiko==2.0.2
当尝试使用paramiko ssh到Aruba设备时,我得到以下错误:
paramiko.ssh_exception。SSHException:不兼容的ssh peer (no acceptable key algorithm)
升级paramiko解决了这个问题:
sudo pip install paramiko --upgrade
如果其他人在使用pip install paramiko --upgrade
升级后仍然有这个问题,请确保您没有在系统范围内安装paramiko,因为它将在pip之前加载,您可以使用dpkg -l | grep paramiko
检查它,如果它已安装,请删除它并通过pip安装
对我来说,我升级了paramiko的版本,它解决了问题。具体来说,我最初通过Ubuntu 14.04 python-paramiko包安装了paramiko,并将其替换为最新的使用pip(1.10 -> 1.16)。
这可能对OP的情况没有帮助,但希望它可以帮助其他有相同错误的人。
我遇到了这样一种情况:一个脚本可以很好地SSH到系统中,但是另一个类似的脚本使用相同的
时会失败。paramiko.SSHException: Incompatible ssh peer (no acceptable kex algorithm)
错误。
情况原来是我的脚本顶部的shebang行:
#!/usr/bin/python
会失败,而
#!/usr/bin/env python
会成功。
我在我的系统上使用virtualenvs,因此失败的/usr/bin/python
版本使用的是系统上安装的较旧的Paramiko版本,而/usr/bin/env python
版本使用的是我的virtualenv中较新的Paramiko安装。
该错误是在您的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', 'zlib@openssh.com'] server compress:['none', 'zlib@openssh.com'] 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
我最近在将服务器从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: Incompatible ssh peer (no acceptable host key)
正如roman之前所说,我所需要的只是:
pip install --upgrade paramiko
...
Successfully installed paramiko-2.11.0
只是想用我的背景来说明他的有用的答案,以表明它仍然是相关的。