Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSH tunnel and port forwarding through a bastion machine gives connection refused error

Tags:

ssh

ssh-tunnel

I have jupyter notebook running on a server machine that I can ssh into through a bastion machine. I want to access the notebook on my local machine.

enter image description here

Here is what I tried after running jupyter on the server machine:

ssh -f -N -L local_machine_port:server_machine_IP:server_machine_port_hosting_jupyter username@bastion_machine_ip

Whenever I try to access http://localhost:local_machine_port or http://127.0.0.1:local_machine_portI get

debug1: client_input_global_request: rtype [email protected] 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

What should I do?

like image 734
A_Matar Avatar asked Sep 13 '25 23:09

A_Matar


1 Answers

Try to add --ip 0.0.0.0 option to jupyter notebook command

You can follow the steps listed below:

 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
like image 57
Mohammed Ali Avatar answered Sep 17 '25 19:09

Mohammed Ali