无法使用 Paramiko 包连接到服务器

Unable to connect to server using Paramiko package

我在 Python 中尝试使用端口 2022(不是 22)的 SSH 连接到我的服务器。所以我编写了以下使用 Paramiko 包的代码:

import sys
import paramiko

try:
  client = paramiko.SSHClient()
  client.load_system_host_keys()
  client.set_missing_host_key_policy(paramiko.WarningPolicy)
  client.connect('ccap@10.40.2.222', '2022', '', 'ccap')
finally:
  client.close()

但是当我 运行 它在我的 IDE (PyCharm) 中时,我收到以下错误:

/usr/local/lib/python3.5/dist-packages/paramiko/ecdsakey.py:164: CryptographyDeprecationWarning: Support for unsafe construction of public numbers from encoded data will be removed in a future version. Please use EllipticCurvePublicKey.from_encoded_point self.ecdsa_curve.curve_class(), pointinfo

Traceback (most recent call last):
File "/home/mshapirs/PycharmProjects/OnlineTest.py/OnlineTest.py", line 9, in client.connect('ccap@10.40.2.222', '2022', '', 'ccap')

File "/usr/local/lib/python3.5/dist-packages/paramiko/client.py", line 334, in connect to_try = list(self._families_and_addresses(hostname, port))

File "/usr/local/lib/python3.5/dist-packages/paramiko/client.py", line 204, in _families_and_addresses hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM

File "/usr/lib/python3.5/socket.py", line 733, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):

socket.gaierror: [Errno -2] Name or service not known

您应该将用户名作为单独的参数提供,而不是添加到主机地址之前。

Look at the docs for .connect。它有 usernamehostname 分别列出。