通过堡垒机的 SSH 隧道和端口转发会导致连接被拒绝错误

标签 ssh ssh-tunnel

我在服务器机器上运行了 jupyter notebook,我可以通过 bastion 机器 ssh 进入。我想访问本地计算机上的笔记本。

enter image description here

这是我在服务器机器上运行 jupyter 后的尝试:

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我得到

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

我该怎么办?

最佳答案

尝试在 jupyter notebook 命令中添加 --ip 0.0.0.0 选项

您可以按照下面列出的步骤操作:

 1. Run ssh on local machine:
     ssh -L local_machine_port:server_machine_IP:server_machine_port_hosting_jupyter username@bastion_machine_ip
 2. Run jupyter notebook on remote server:
     jupyter notebook --ip 0.0.0.0 --port server_machine_port_hosting_jupyter  
 3. Open browser on localmachine:
     http://localhost:local_machine_port

关于通过堡垒机的 SSH 隧道和端口转发会导致连接被拒绝错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63717748/

相关文章:

docker - 从 Docker 容器显示 Android Studio GUI,同时通过 headless Ubuntu 服务器进行 SSH 隧道传输

ssl - Google Sitemap Generator - 在 Linux 上设置 HTTPS

python - 使用身份的Fabrics 2.x ssh连接无法正常工作

python - Paramiko SSHClient无法在远程计算机上执行整个shell脚本

ruby-on-rails - 未找到将 rails 应用程序部署到 digital ocean dokku ssh key

ssh - SFTP,SSH和SSH隧道

EC2 实例重启后 SSH 隧道停止工作

python - 使用 PyCharm 远程调试器时收到 "/: Event not found."

macos - 如何使用 SSH 将 IntelliJ 连接到 GitHub