【问题标题】:Translate ssh tunnel command to SSHTunnelForwarder code?将 ssh 隧道命令翻译成 SSHTunnelForwarder 代码?
【发布时间】:2019-06-20 09:23:19
【问题描述】:

我正在尝试将此 ssh 隧道命令转换为使用 python SSHTunnelForwarder。这有效:

ssh -i mypk -N -L 5901:localhost:5432 user@100.0.0.100

我试过了:

with SSHTunnelForwarder(
        ('localhost', 5901),
        ssh_username='user',
        ssh_private_key=path_to_mypk,
        remote_bind_address=('100.0.0.100', 5432)

但出现错误(在暂停几秒钟后):“无法建立与 SSH 网关的会话”。我该怎么办?

【问题讨论】:

    标签: python ssh ssh-tunnel


    【解决方案1】:

    我缺少的部分是从服务器的角度使用“localhost”。以下作品:

    with SSHTunnelForwarder(
            ('100.0.0.100', 22),
            ssh_username='user',
            ssh_private_key=path_to_mypk,
            remote_bind_address=('localhost', 5432), # localhost from server's perspective
            local_bind_address=('localhost', 5901)  # any available port
    )
    

    【讨论】:

      猜你喜欢
      • 2020-11-07
      • 2014-05-12
      • 2020-08-07
      • 2020-06-17
      • 2020-10-26
      • 1970-01-01
      • 1970-01-01
      • 2020-10-16
      • 2017-12-20
      相关资源
      最近更新 更多