4

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 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

What should I do?

A_Matar
  • 2,210
  • 3
  • 31
  • 53
  • Does this answer your question? [SSH -L connection successful, but localhost port forwarding not working "channel 3: open failed: connect failed: Connection refused"](https://stackoverflow.com/questions/18705453/ssh-l-connection-successful-but-localhost-port-forwarding-not-working-channel) – Kenster Sep 03 '20 at 13:01

2 Answers2

3

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
Mohammed Ali
  • 166
  • 1
  • 5
0

edit

Sorry, I only just realized you are connecting with ssh to the bastion machine and not to the remote server running jupyter.

In that case you probably first need to establish a ssh connection to the remote server using the bastion machine, see this answer on how to do that.

original answer

Are you replacing server_machine_IP in your command with the external IP addres of the machine? i.e. something like

ssh -f -N -L 7001:10.45.12.34:7001 username@bastion_machine_ip

If so this will forward your local port to the specified port on the remote server on its external IP address. But if jupyter on that host is not listening on that IP - but only on localhost - the connection will be refused.

If jupyter is only listening to local connection you may try @Mohammed's answer to let jupyter listen on the external IP. Or try the following

ssh -f -N -L 7001:localhost:7001 username@bastion_machine_ip

and open http://localhost:local_machine_port on your local machine: this will forward from the port on your local machine to the port on localhost on the remote machine, i.e. for jupyter on the remote host this will look like a connection coming from the local machine (which is the remote server).

acran
  • 7,070
  • 1
  • 18
  • 35