使用pssh2客户端时发生ParallelSSH会话握手错误

2024-09-30 05:32:47 发布

您现在位置:Python中文网/ 问答频道 /正文

使用parallel-ssh模块,我尝试使用Natinve客户机运行SSH命令,但是得到了SessionHandshakeError。如果我改用Paramiko客户端,一切都很好。我遇到了my_pkey.pubrequirementmy_pkey在同一个目录中。在

下面是我使用本机客户机的代码(将实际IP改为'ip1''ip2'):

from pssh.pssh2_client import ParallelSSHClient

pkey = os.path.dirname(os.path.abspath(__file__)) + '/my_pkey'
hosts = ['ip1', 'ip2']
client = ParallelSSHClient(hosts, user='root', pkey=pkey)
output = client.run_command('hostname')
for host, host_output in output.items():
    for line in host_output.stdout:
        print(line)

获取此错误:

^{pr2}$

以下是我使用Paramiko客户端的代码(将实际IP更改为“ip1”和“ip2”):

from pssh.pssh_client import ParallelSSHClient
from pssh.utils import load_private_key

key_path = os.path.dirname(os.path.abspath(__file__)) + '/my_pkey'
pkey = load_private_key(key_path)
hosts = ['ip1', 'ip2']
client = ParallelSSHClient(hosts, user='root', pkey=pkey)
output = client.run_command('hostname')
for host, host_output in output.items():
    for line in host_output.stdout:
        print(line)

而且很管用。这是输出(我应该关心警告吗?)公司名称:

C:\Program Files (x86)\Python36-32\lib\site-packages\paramiko\ecdsakey.py:202: CryptographyDeprecationWarning: signer and verifier have been deprecated. Please use sign and verify instead.
  signature, ec.ECDSA(self.ecdsa_curve.hash_object())
C:\Program Files (x86)\Python36-32\lib\site-packages\paramiko\rsakey.py:110: CryptographyDeprecationWarning: signer and verifier have been deprecated. Please use sign and verify instead.
  algorithm=hashes.SHA1(),
ip1.hostname
ip2.hostname

Process finished with exit code 0

我对本地客户做了什么错事?在


Tags: pathinclienthostforoutputosmy
2条回答

这个错误被追踪到在Windows上用于libssh2的WinCNG后端-它不支持SHA-256主机密钥哈希,这在OpenSSH服务器的最新版本中是默认的。在

parallel-ssh1.6.0latest version通过将Windows后端切换到OpenSSL以获得更好的兼容性并匹配OSX和Linux二进制控制盘,解决了这个问题。在

有关详细信息,请参见release notes。在

一些解释,我从Panos在谷歌小组线程。这对我没有帮助,但也许对其他人有帮助。在

A -5 error is defined as a key exchange error in libssh2. It sounds like the key type is not supported by libssh2 and paramiko shows 'ecdsakey.py' being used. ECDSA keys are not currently supported by libssh2 (PR pending).

The warning are from paramiko itself, can't say if they matter.

Better exceptions for native client errors are being worked on for next release.

So for a private key 'my_pkey', there should be a 'my_pkey.pub' in same directory.

It may also be a case of the SSH server's key not being supported by the native client (same limitations as user keys) which would explain the key exchange error. Can check the type of key configured for the server in /etc/ssh/sshd_config, HostKey entry. There should be at least one non-ECDSA key configured, eg:

HostKey /etc/ssh/ssh_host_rsa_key HostKey /etc/ssh/ssh_host_dsa_key HostKey /etc/ssh/ssh_host_ecdsa_key

If there is only a ECDSA key entry, the native client will not be able to connect.

相关问题 更多 >

    热门问题