使用sshtunnel模块的SSH隧道不允许输入空密码

时间:2019-06-05 11:22:38

标签: python ssh-tunnel

我正在尝试使用sshtunnel模块从Windows机器启动到Linux机器上没有密码的ssh隧道。

from sshtunnel import SSHTunnelForwarder

server = SSHTunnelForwarder(
    '172.30.1.101',
    ssh_username="root",
    ssh_password="",
    remote_bind_address=('127.0.0.1', 1883)
)

server.start()

我一直在犯错误。

remote_bind_address=('127.0.0.1', 1883)
  File "C:\Users\Chirag.Acharya\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sshtunnel.py", line 905, in __init__
    logger=self.logger
  File "C:\Users\Chirag.Acharya\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sshtunnel.py", line 1096, in _consolidate_auth
    raise ValueError('No password or public key available!')
ValueError: No password or public key available!

该怎么办!我的ssh不需要任何密码! root用户没有设置登录密码。

1 个答案:

答案 0 :(得分:0)

将密钥路径添加到SSHTunnelForwarder

server = SSHTunnelForwarder(
    '172.30.1.101',
    ssh_username="root",
    ssh_password="",
    ssh_pkey="/var/ssh/rsa_key",
    remote_bind_address=('127.0.0.1', 1883)
)