首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过堡垒机进行的SSH隧道和端口转发导致连接拒绝错误。

通过堡垒机进行的SSH隧道和端口转发导致连接拒绝错误。
EN

Stack Overflow用户
提问于 2020-09-03 06:04:31
回答 1查看 3.1K关注 0票数 3

我有一个jupyter笔记本运行在服务器上,我可以通过堡垒机器进入服务器。我想访问本地机器上的笔记本。

以下是我在服务器上运行jupyter之后所做的尝试:

代码语言:javascript
复制
ssh -f -N -L local_machine_port:server_machine_IP:server_machine_port_hosting_jupyter username@bastion_machine_ip

每当我尝试访问http://localhost:local_machine_porthttp://127.0.0.1:local_machine_port时,我都会得到

代码语言:javascript
复制
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: Connection to port 7001 forwarding to <server ip> port <server port> requested.
debug1: channel 2: new [direct-tcpip]
debug1: Connection to port 7001 forwarding to <server ip> port <server port> requested.
debug1: channel 3: new [direct-tcpip]
channel 2: open failed: connect failed: Connection refused
debug1: channel 2: free: direct-tcpip: listening port 7001 for <server ip> port <server port>, connect from 127.0.0.1 port 43276 to 127.0.0.1 port 7001, nchannels 4
channel 3: open failed: connect failed: Connection refused
debug1: channel 3: free: direct-tcpip: listening port 7001 for <server ip> port <server port>, connect from 127.0.0.1 port 43278 to 127.0.0.1 port 7001, nchannels 3
debug1: Connection to port 7001 forwarding to 192.168.2.38 port 6006 requested.
debug1: channel 2: new [direct-tcpip]
channel 2: open failed: connect failed: Connection refused
debug1: channel 2: free: direct-tcpip: listening port 7001 for <server ip> port <server port>, connect from 127.0.0.1 port 43280 to 127.0.0.1 port 7001, nchannels 3

我该怎么办?

EN

回答 1

Stack Overflow用户

发布于 2020-09-06 21:07:04

编辑

对不起,我只是刚刚意识到您正与ssh连接到堡垒机器,而不是连接到运行jupyter的远程服务器。

在这种情况下,您可能首先需要使用堡垒机器建立到远程服务器的ssh连接,参见this answer on how to do that

原始答案

您是否将命令中的server_machine_IP替换为机器的外部IP地址?例如,类似

代码语言:javascript
复制
ssh -f -N -L 7001:10.45.12.34:7001 username@bastion_machine_ip

如果是这样的话,这将将本地端口转发到远程服务器上的外部IP地址上的指定端口。但是,如果该主机上的jupyter没有监听该IP,而是只在本地主机上侦听,则连接将被拒绝。

如果jupyter只监听本地连接,您可以尝试@Mohammed's answer让jupyter监听外部IP。或尝试以下操作

代码语言:javascript
复制
ssh -f -N -L 7001:localhost:7001 username@bastion_machine_ip

并在本地计算机上打开http://localhost:local_machine_port:这将从本地计算机上的端口转发到远程计算机上的localhost 上的端口,即对于远程主机上的jupyter来说,这看起来像来自本地计算机(即远程服务器)的连接。

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

https://stackoverflow.com/questions/63717748

复制
相关文章

相似问题

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