簡體   English   中英

如何在 python SFTP/paramiko connexion 中解決錯誤不兼容的 ssh 服務器(沒有可接受的密碼)?

[英]How to resolve error Incompatible ssh server (no acceptable ciphers) in python SFTP/paramiko connexion?

我是 python 的初學者,我希望通過 SFTP 協議將文件從我的計算機(Windows 10 21H2)自動傳輸到 Linux 服務器(Rocky Linux 8.6)。 我正在使用帶有密碼的密鑰對進行身份驗證。

連接不成功。 我嘗試了很多組合並在stackoverflow上遇到了很多問題,但沒有成功......

import pysftp

host,port = 'monServeur.domaine.fr',22
username='pmartin'
pkey='C:/Users/pmartin/.ssh/myPrivateKey'
passphrase='mypassphrase'

with pysftp.Connection(host=host, username=username, private_key=pkey, port=22, private_key_pass=passphrase) as sftp:
    with sftp.cwd('/home/pmartin'):
        for entry in sftp.listdir_attr():
            print(entry.filename)

返回錯誤:

C:\programmation\python>"C:/Program Files/Python310/python.exe" c:/programmation/python/ftptls.py
Exception (client): Incompatible ssh server (no acceptable ciphers)
Traceback (most recent call last):
  File "C:\Users\omarie\AppData\Roaming\Python\Python310\site-packages\paramiko\transport.py", line 2138, in run
    self._handler_table[ptype](self, m)
  File "C:\Users\omarie\AppData\Roaming\Python\Python310\site-packages\paramiko\transport.py", line 2258, in _negotiate_keys
    self._parse_kex_init(m)
  File "C:\Users\omarie\AppData\Roaming\Python\Python310\site-packages\paramiko\transport.py", line 2511, in _parse_kex_init
    raise IncompatiblePeer(
paramiko.ssh_exception.IncompatiblePeer: Incompatible ssh server (no acceptable ciphers)

Traceback (most recent call last):
  File "c:\programmation\python\ftptls.py", line 9, in <module>
    with pysftp.Connection(host, username, pkey, None, 22, passphrase, ['aes128-cbc','aes192-cbc','aes256-cbc','aes128-ctr','aes192-ctr','aes256-ctr']) as sftp:
  File "C:\Users\omarie\AppData\Roaming\Python\Python310\site-packages\pysftp\__init__.py", line 143, in __init__
    self._transport.connect(**self._tconnect)
  File "C:\Users\omarie\AppData\Roaming\Python\Python310\site-packages\paramiko\transport.py", line 1346, in connect
    self.start_client()
  File "C:\Users\omarie\AppData\Roaming\Python\Python310\site-packages\paramiko\transport.py", line 699, in start_client
    raise e
  File "C:\Users\omarie\AppData\Roaming\Python\Python310\site-packages\paramiko\transport.py", line 2138, in run
    self._handler_table[ptype](self, m)
  File "C:\Users\omarie\AppData\Roaming\Python\Python310\site-packages\paramiko\transport.py", line 2258, in _negotiate_keys
    self._parse_kex_init(m)
  File "C:\Users\omarie\AppData\Roaming\Python\Python310\site-packages\paramiko\transport.py", line 2511, in _parse_kex_init
    raise IncompatiblePeer(
paramiko.ssh_exception.IncompatiblePeer: Incompatible ssh server (no acceptable ciphers)

版本:

Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32

模塊:

  • 名稱:密碼學版本:37.0.2
  • 名稱:paramiko 版本:2.11.0
  • 名稱:pysftp 版本:0.2.9

服務器上的密碼:

[monServeur ~/.ssh]$ ssh -Q cipher
3des-cbc
aes128-cbc
aes192-cbc
aes256-cbc
rijndael-cbc@lysator.liu.se
aes128-ctr
aes192-ctr
aes256-ctr
aes128-gcm@openssh.com
aes256-gcm@openssh.com
chacha20-poly1305@openssh.com

我試圖像這樣在 pysftp 命令中添加密碼,但沒有成功:

with pysftp.Connection(host, username, pkey, None, 22, passphrase, ['aes128-cbc','aes192-cbc','aes256-cbc','aes128-ctr','aes192-ctr','aes256-ctr']) as sftp:

我可以使用 FileZilla 和 Cyber​​duck 使用密鑰對和密碼進行傳輸,而不會出現這種“密碼問題”。

有人可以給我一個線索嗎?

添加:paramiko 日志文件

DEBUG:paramiko.transport:starting thread (client mode): 0x1bf1a6b0
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.11.0
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-OpenSSH_8.0
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_8.0)
DEBUG:paramiko.transport:=== Key exchange possibilities ===
DEBUG:paramiko.transport:kex algos: curve25519-sha256@libssh.org
DEBUG:paramiko.transport:server key: rsa-sha2-512, rsa-sha2-256, ssh-rsa, ssh-ed25519
DEBUG:paramiko.transport:client encrypt: chacha20-poly1305@openssh.com, aes256-gcm@openssh.com   
DEBUG:paramiko.transport:server encrypt: chacha20-poly1305@openssh.com, aes256-gcm@openssh.com   
DEBUG:paramiko.transport:client mac: hmac-sha2-512-etm@openssh.com, hmac-sha2-256-etm@openssh.com
DEBUG:paramiko.transport:server mac: hmac-sha2-512-etm@openssh.com, hmac-sha2-256-etm@openssh.com
DEBUG:paramiko.transport:client compress: none, zlib@openssh.com
DEBUG:paramiko.transport:server compress: none, zlib@openssh.com
DEBUG:paramiko.transport:client lang: <none>
DEBUG:paramiko.transport:server lang: <none>
DEBUG:paramiko.transport:kex follows: False
DEBUG:paramiko.transport:=== Key exchange agreements ===
DEBUG:paramiko.transport:Kex: curve25519-sha256@libssh.org
DEBUG:paramiko.transport:HostKey: ssh-ed25519
ERROR:paramiko.transport:Exception (client): Incompatible ssh server (no acceptable ciphers)

您的服務器僅支持兩種專有的 OpenSSH 密碼:

DEBUG:paramiko.transport:client encrypt: chacha20-poly1305@openssh.com, aes256-gcm@openssh.com   
DEBUG:paramiko.transport:server encrypt: chacha20-poly1305@openssh.com, aes256-gcm@openssh.com   

這確實是相當有限的一套。

Paramiko 不支持這些。

您必須重新配置服務器以支持 Paramiko 所做的一些密碼。

暫無
暫無

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

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