首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ParallelSSH - SessionHandshakeError在使用pssh2_client时

ParallelSSH - SessionHandshakeError在使用pssh2_client时
EN

Stack Overflow用户
提问于 2018-03-19 14:36:15
回答 2查看 768关注 0票数 0

使用并行ssh模块,我尝试使用Natinve运行SSH命令,但获取SessionHandshakeError。如果我用Paramiko客户端,一切正常。我遇到了要求 of my_pkey.pub,它与my_pkey位于同一个目录中。

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

代码语言:javascript
复制
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)

获取此错误:

代码语言:javascript
复制
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pssh\ssh2_client.py", line 123, in _init
    self.session.handshake(self.sock)
  File "ssh2\session.pyx", line 81, in ssh2.session.Session.handshake
ssh2.exceptions.SessionHandshakeError: ('SSH session handshake failed with error code %s', -5)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pssh\ssh2_client.py", line 123, in _init
    self.session.handshake(self.sock)
  File "ssh2\session.pyx", line 81, in ssh2.session.Session.handshake
ssh2.exceptions.SessionHandshakeError: ('SSH session handshake failed with error code %s', -5)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pssh\ssh2_client.py", line 123, in _init
    self.session.handshake(self.sock)
  File "ssh2\session.pyx", line 81, in ssh2.session.Session.handshake
ssh2.exceptions.SessionHandshakeError: ('SSH session handshake failed with error code %s', -5)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/NazimokPP/Desktop/AnchorFree/QA-Automation/nodetest/nodetest.py", line 57, in <module>
    main(args.server_domain, args.test_type)
  File "C:/Users/NazimokPP/Desktop/AnchorFree/QA-Automation/nodetest/nodetest.py", line 45, in main
    output = client.run_command('hostname')
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pssh\pssh2_client.py", line 182, in run_command
    encoding=encoding, use_pty=use_pty, timeout=timeout)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pssh\base_pssh.py", line 91, in run_command
    self.get_output(cmd, output)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pssh\base_pssh.py", line 136, in get_output
    (channel, host, stdout, stderr, stdin) = cmd.get()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\gevent\greenlet.py", line 482, in get
    self._raise_exception()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\gevent\greenlet.py", line 159, in _raise_exception
    reraise(*self.exc_info)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\gevent\_compat.py", line 33, in reraise
    raise value.with_traceback(tb)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\gevent\greenlet.py", line 536, in run
    result = self._run(*self.args, **self.kwargs)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pssh\pssh2_client.py", line 188, in _run_command
    self._make_ssh_client(host)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\pssh\pssh2_client.py", line 313, in _make_ssh_client
    allow_agent=self.allow_agent, retry_delay=self.retry_delay)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pssh\ssh2_client.py", line 107, in __init__
    THREAD_POOL.apply(self._init)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\gevent\pool.py", line 325, in apply
    return self.spawn(func, *args, **kwds).get()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\gevent\event.py", line 385, in get
    return self.get(block=False)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\gevent\event.py", line 375, in get
    return self._raise_exception()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\gevent\event.py", line 355, in _raise_exception
    reraise(*self.exc_info)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\gevent\_compat.py", line 33, in reraise
    raise value.with_traceback(tb)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\gevent\threadpool.py", line 211, in _worker
    value = func(*args, **kwargs)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pssh\ssh2_client.py", line 126, in _init
    return self._connect_init_retry(retries)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pssh\ssh2_client.py", line 116, in _connect_init_retry
    return self._init(retries=retries)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pssh\ssh2_client.py", line 126, in _init
    return self._connect_init_retry(retries)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pssh\ssh2_client.py", line 116, in _connect_init_retry
    return self._init(retries=retries)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pssh\ssh2_client.py", line 128, in _init
    raise SessionError(msg, self.host, self.port, ex)
pssh.exceptions.SessionError: ('Error connecting to host %s:%s - %s', 'ip1', 22, SessionHandshakeError('SSH session handshake failed with error code %s', -5))

Process finished with exit code 1

下面是我的代码,它使用Paramiko客户端(将真实的ip2更改为“ip1”和“ip2”):

代码语言:javascript
复制
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)

而且它是有效的。这是输出(我应该关心警告吗?):

代码语言:javascript
复制
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

我对本地客户做了什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-05-22 12:47:24

此错误被跟踪到用于libssh2libssh2后端,它不支持SHA-256主机密钥散列,这在最近版本的OpenSSH服务器中是默认的。

最新版本 of parallel-ssh1.6.0通过将Windows后端切换到OpenSSL来解决这个问题,以获得更好的兼容性,并与OSX和Linux二进制引擎相匹配。

有关更多详细信息,请参阅发布说明

票数 1
EN

Stack Overflow用户

发布于 2018-04-10 15:13:18

我从Groups的文章中得到了一些解释。这对我没有帮助,但也许会对其他人有所帮助。

-5错误定义为libssh2中的密钥交换错误。听起来关键类型不受libssh2的支持,而paramiko则显示正在使用的“ecdsakey.py”。libssh2目前不支持ECDSA密钥(PR待定)。 警告来自paramiko本身,不能说它们是否重要。 针对本机客户端错误的更好的异常正在为下一个版本进行处理。

_

因此,对于私钥“my_pkey”,同一目录中应该有“my_pkey.pub”。 也可能是本机客户端不支持SSH服务器的密钥(与用户密钥相同的限制),这将解释密钥交换错误。可以检查/etc/ssh/sshd_config、HostKey条目中为服务器配置的密钥类型。应该至少配置一个非ECDSA密钥,例如: HostKey /etc/ssh/ssh_host_rsa_key HostKey /etc/ssh/ssh_host_dsa_key HostKey /etc/ssh/ssh_host_ecdsa_key 如果只有ECDSA密钥条目,则本机客户端将无法连接。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49365521

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档