- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用 Python 连接到远程 SFTP 服务器,特别是 pysftp。在 Windows 上使用 FileZilla 或 WinSCP,或者在 Linux(特别是 AWS Linux)上使用 sftp
,我可以毫无问题地进行连接。连接失败并出现错误
SSHException: Negotiation failed.
是否有我遗漏的设置?
我最初假设问题出在主机 key 上,但是无论是传递主机 key 文件,还是将主机 key 设置为 None(使用 pysftp),我都得到了相同的结果
这似乎是在连接的早期发生的,就好像我使用随机用户名或密码我得到完全相同的结果
import pysftp
import logging
logging.basicConfig(level=logging.DEBUG)
cnopts = pysftp.CnOpts()
cnopts.hostkeys.load( 'C:\Temp\known_hosts')
cnopts.log = 'C:\Temp\\ftplog.txt'
cnopts.hostkeys = None
with pysftp.Connection(port = 2222,
host = 'ftp.apxgroup.com',
username = 'my.username',
password = 'thepassword',
cnopts = cnopts) as srv:
data = srv.listdir()
for i in data:
print(i)
调试信息如下:
DEBUG:paramiko.transport:starting thread (client mode): 0x4b1deef0
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.6.0
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-srtSSHServer_11.00
INFO:paramiko.transport:Connected (version 2.0, client srtSSHServer_11.00)
DEBUG:paramiko.transport:kex algos:['diffie-hellman-group14-sha256', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group14-sha1', 'diffie-hellman-group-exchange-sha1', 'diffie-hellman-group1-sha1', 'diffie-hellman-group-exchange-sha512@ssh.com', 'diffie-hellman-group15-sha256', 'diffie-hellman-group15-sha512', 'diffie-hellman-group16-sha256', 'diffie-hellman-group16-sha512', 'diffie-hellman-group17-sha512', 'diffie-hellman-group18-sha512'] server key:['ssh-rsa'] client encrypt:['aes256-cbc', 'twofish256-cbc', 'twofish-cbc', 'aes128-cbc', 'twofish128-cbc', 'blowfish-cbc', '3des-ctr', '3des-cbc', 'cast128-cbc'] server encrypt:['aes256-cbc', 'twofish256-cbc', 'twofish-cbc', 'aes128-cbc', 'twofish128-cbc', 'blowfish-cbc', '3des-ctr', '3des-cbc', 'cast128-cbc'] client mac:['hmac-sha1', 'hmac-sha2-224', 'hmac-sha2-256', 'hmac-sha2-384', 'hmac-sha2-512', 'hmac-md5'] server mac:['hmac-sha1', 'hmac-sha2-224', 'hmac-sha2-256', 'hmac-sha2-384', 'hmac-sha2-512', 'hmac-md5'] client compress:['none'] server compress:['none'] client lang:[''] server lang:[''] kex follows?False
DEBUG:paramiko.transport:Kex agreed: diffie-hellman-group16-sha512
DEBUG:paramiko.transport:HostKey agreed: ssh-rsa
DEBUG:paramiko.transport:Cipher agreed: aes128-cbc
DEBUG:paramiko.transport:MAC agreed: hmac-sha2-256
DEBUG:paramiko.transport:Compression agreed: none
INFO:paramiko.transport:Disconnect (code 3): invalid DH value
Traceback (most recent call last):
File "<ipython-input-25-99a886da3f3d>", line 1, in <module>
runfile('O:/Moorlands/Software/Python/untitled0.py', wdir='O:/Moorlands/Software/Python')
File "C:\Users\Mark\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
execfile(filename, namespace)
File "C:\Users\Mark\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "O:/Moorlands/Software/Python/untitled0.py", line 22, in <module>
cnopts = cnopts) as srv:
File "C:\Users\Mark\Anaconda3\lib\site-packages\pysftp\__init__.py", line 143, in __init__
self._transport.connect(**self._tconnect)
File "C:\Users\Mark\Anaconda3\lib\site-packages\paramiko\transport.py", line 1291, in connect
self.start_client()
File "C:\Users\Mark\Anaconda3\lib\site-packages\paramiko\transport.py", line 661, in start_client
raise SSHException("Negotiation failed.")
SSHException: Negotiation failed.
如果我(成功)通过启用日志记录的 sftp
连接,我会得到以下日志:
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug1: Connecting to ftp.apxgroup.com [185.115.188.136] port 2222.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/ec2-user/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ec2-user/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ec2-user/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ec2-user/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ec2-user/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ec2-user/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ec2-user/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ec2-user/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version srtSSHServer_11.00
debug1: no match: srtSSHServer_11.00
debug1: Authenticating to ftp.apxgroup.com:2222 as 'my.username'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: diffie-hellman-group-exchange-sha256
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: aes128-cbc MAC: hmac-sha2-256 compression: none
debug1: kex: client->server cipher: aes128-cbc MAC: hmac-sha2-256 compression: none
debug1: kex: diffie-hellman-group-exchange-sha256 need=32 dh_need=32
debug1: kex: diffie-hellman-group-exchange-sha256 need=32 dh_need=32
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<8192<8192) sent
debug1: got SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: got SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: ssh-rsa SHA256:kJuxrXQ83BRlECmULsScHmC4qKUwaFig0ZrzV929qLM
debug1: checking without port identifier
debug1: Host 'ftp.apxgroup.com' is known and matches the RSA host key.
debug1: Found key in /home/ec2-user/.ssh/known_hosts:2
RSA host key for IP address '185.115.188.136' not in list of known hosts.
debug1: found matching key w/out port
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/ec2-user/.ssh/id_rsa
debug1: Trying private key: /home/ec2-user/.ssh/id_dsa
debug1: Trying private key: /home/ec2-user/.ssh/id_ecdsa
debug1: Trying private key: /home/ec2-user/.ssh/id_ed25519
debug1: Next authentication method: password
my.username@ftp.apxgroup.com's password:
debug1: Authentication succeeded (password).
Authenticated to ftp.apxgroup.com ([185.115.188.136]:2222).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending subsystem: sftp
Connected to ftp.apxgroup.com.
最佳答案
按照 Martin Prikryl 的建议,从默认值更改 paramiko.Transport._preferred_kex
paramiko.Transport._preferred_kex = ('curve25519-sha256@libssh.org',
'ecdh-sha2-nistp256',
'ecdh-sha2-nistp384',
'ecdh-sha2-nistp521',
'diffie-hellman-group16-sha512',
'diffie-hellman-group-exchange-sha256',
'diffie-hellman-group14-sha256',
'diffie-hellman-group-exchange-sha1',
'diffie-hellman-group14-sha1',
'diffie-hellman-group1-sha1')
到
paramiko.Transport._preferred_kex = ('diffie-hellman-group-exchange-sha256',
'diffie-hellman-group14-sha256',
'diffie-hellman-group-exchange-sha1',
'diffie-hellman-group14-sha1',
'diffie-hellman-group1-sha1')
解决了这个问题。
关于python - Paramiko/pysftp 连接失败,出现 "Negotiation failed/invalid DH value",但是 GUI 和 sftp 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58014258/
我在构建 debian 软件包时遇到了问题。 至于规则文件的文件:https://www.debian.org/doc/manuals/maint-guide/dreq.en.html#rules d
我使用某些 g 生成了一个 Diffie-Hellman key 和 p参数,像这样: $ cat dhparam.pem -----BEGIN DH PARAMETERS----- MIIBCAKC
我需要支持 Diffie Hellman 加密,现在为了测试这个我需要创建一个带有 DH key 参数的证书,例如。 key 长度 - 2048 等 据我所知,DH 不适用于自签名证书,因此基本上我需
我们最近升级了我们的一个工具(使用 java 实现),现在它很难连接到我们公司的一个内部端点。对于其他端点,它工作正常。假设它不起作用的端点是 xyz.abc.com 我们每次看到的错误是 javax
我的一份文档说 Generate the private and public keys using the Diffie-Hellman parameters (‘p’ and ‘g’). The
我正在构建一个 debian 软件包,它使用其他名称将多个配置文件安装到不同的位置。为此,我想使用 dh-exec 安装重命名功能。 在 control 文件中,我将 dh-exec 声明为 Buil
根据 RFC 4419,在客户端 DH key 交换初始化消息之前,服务器将向客户端发送一个大的安全素数 (p) 和子组 (g) 的生成器。我正在查看一个wireshark 数据包捕获,但没有看到它们
运行 java 代码时出现以下异常'无法生成 DH key 对'(我使用 TLSv1.2)。 我将素数大小从 1024 转换为 2048,但总是遇到相同的错误。 然后我禁用了 DH,它运行得很好。 但
刚刚开始使用 dh-virtualenv,并一直在关注 https://nylas.com/blog/packaging-deploying-python/ 上的教程。 我有一个简单的 2 文件测试应
我在通过具有 Java 版本 1.6.0_26 的代理服务器访问第三方 URL 时收到以下错误。 java.lang.RuntimeException: Could not generate DH
我正在尝试使用 CA 证书在 activemq 中设置一个安全的 websocket,但我一直在浏览器中收到此消息: SSL received a weak ephemeral Diffie-Hell
我正在尝试使用一个简单的 PERL 脚本连接到一个关闭的服务器 - 一台空调 #!/usr/bin/perl use 5.10.1; use warnings; use strict; use IO:
尝试使用 suds 发送 SOAP 请求, 我正在使用 Python 2.7.6 . 我不是很精通安全我被引导相信无论是我的机器或服务器机器上的安全 key 太小,我不知道如何解决。我是否会生成一些新
我编写了一个使用 openssl 的程序,并将其 dockerized。 但是当我尝试使用 python:3.7 基础镜像时,出现以下错误: [SSL: DH_KEY_TOO_SMALL] dh ke
我听说 SSH 使用 RSA 和 diffie hellman。我也知道 key 交换过程如下。 客户端初始化 服务器初始化 key 交换请求 回复 新 key 它在 key 交换过程中使用 DH。
我尝试在 Eclipse 中提交/更新项目时遇到错误(在终端中没有问题)。 窗口详细信息: org.apache.subversion.javahl.ClientException: svn: E17
我正在 Anypoint Studio 中创建一个简单的 Mule 流程 - 它定期轮询目录,当文件放置在目录中时,它会将其发送到 SFTP 服务器。但是,当应用程序开始与服务器协商安全连接时,它会失
我正在尝试将 Debian 打包与自包含的基于 virtualenv 的 Python 部署相结合 this使用 dh-virtualenv 的教程。 debian/兼容: 9 debian/cont
这是我用来生成 DH key 对的代码: KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH"); keyGen.initialize
每次我尝试抓取页面时,例如 HtmlPage page1 = (HtmlPage)client.GetHtmlPage("https://groceries.morrisons.com/"); 我收
我是一名优秀的程序员,十分优秀!