簡體   English   中英

paramiko 不兼容的 ssh 對等體(沒有可接受的 kex 算法)

[英]paramiko Incompatible ssh peer (no acceptable kex algorithm)

嘗試使用 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', '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。

我在服務器端遇到與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進行修改

我升級了paramiko以解決問題:

 sudo pip install paramiko --upgrade

我更新的paramiko版本是:

paramiko==2.0.2

如果其他人仍然在使用pip install paramiko --upgrade升級之后仍然遇到此問題,請確保您沒有安裝系統范圍的paramiko,因為它將在pip之前加載,您可以使用dpkg -l | grep paramiko檢查它dpkg -l | grep paramiko dpkg -l | grep paramiko ,如果已安裝,請將其刪除並通過pip安裝。

對我來說,我升級了paramiko的版本並解決了問題。 具體來說,我最初通過Ubuntu 14.04 python-paramiko軟件包安裝了paramiko,並用最新的pip(1.10 - > 1.16)替換它。

嘗試使用paramiko ssh到Aruba設備時出現以下錯誤:

paramiko.ssh_exception.SSHException:不兼容的ssh peer(沒有可接受的kex算法)

執行paramiko升級解決了這個問題:

sudo pip install paramiko --upgrade

這可能對OP的情況沒有幫助,但希望它可以幫助其他人犯同樣的錯誤。

我遇到一種情況,一個腳本會很好地連接到系統,但另一個類似的腳本會失敗

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)

正如羅曼早些時候所說,我所需要的只是:

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

只是想用我的上下文來說明他的有用答案,以表明它仍然是相關的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM