Debug port forwarding for using Jupyter notebook remotely - ssh

I am trying to use Jupyter notebook on a remote computer. The setup is as follows: I have my home laptop, which can ssh to a specific computer on my university's network (e.g., gateway.myuniv.edu). Once I am logged to gateway.myuniv.edu, I can ssh to the computer on which I would like to run the Jupyter notebook server (e.g. cluster.myuniv.edu).
What works: I can run the server on the gateway and connect to it from my laptop using local port forwarding, as follows:
On gateway.myuniv.edu: $ jupyter notebook --no-browser --port 8888
On my laptop: $ ssh -v -N -L 9000:localhost:8888 myusername#gateway.myuniv.edu
Then on my laptop's browser, I open the url: http://localhost:9000
What doesn't work: I don't want to run the server on the gateway, since I can't do heavy computations there. I tried to do the following:
On cluster.myuniv.edu: $ jupyter notebook --no-browser --port 8888
On my laptop: $ ssh -v -N -L 9000:cluster.myuniv.edu:8888 myusername#gateway.myuniv.edu
Then on my laptop's browser, I open the url: http://localhost:9000. This doesn't work: SSH says that the connection is refused.
I don't understand why this would happen and how to debug this, would be happy for any help. Thanks!

The issue is that you are forwarding port :8888 on cluster.myuniv.edu to port :9000 on gateway.myuniv.edu and then forwarding port :8888 on gateway.myuniv.edu to port 9000 on your laptop.
The solution would the following:
On cluster.myuniv.edu: $ jupyter notebook --no-browser --port 8888
On gateway.myuniv.edu: $ ssh -v -N -L 8888:localhost:8888 myusername#cluster.myuniv.edu
On laptop: $ ssh -v -N -L 9000:localhost:8888 myusername#gateway.myuniv.edu
I would also recommend that you run Jupyter notebook (on the cluster) and the ssh tunneling (on the gateway) using Tmux or Screen so it remains active even if you close terminal

You can use gateway.myuniv.edu as a Jump (ssh -J) host.
So start jupyter notebook on your cluster as you normally do:
jupyter notebook --no-browser --port 8888
On your local laptop: ssh username#cluster.myuniv.edu -J username#gateway.myuniv.edu -L 8888:localhost:8888 -N

Related

Run Jupyter Notebook from SSH to remote server node

I want to run a jupyter notebook from SSH to remote server node.
Steps:
ssh user#remote.server
jupyter notebook --no-browser --port=8887
Steps on my computer:
ssh -N -L localhost:8888:localhost:8887 user#remote.server
run localhost:8888
This works fine. However I want to run this on node1 that is inside user#remote.server, because node1 contains a GPU.
Steps I have done are similar except for this:
ssh -N -L localhost:8888:localhost:8887 user#remote.server "ssh node1"
But this does not work: "channel 2: open failed: connect failed: Connection refused"
Edit: /etc/hosts:
Solution after several attempts, following the answer of #ajz34:
On node1: jupyter notebook --no-browser --port=8886 --ip=127.0.0.1
On server: ssh -N -L 8887:127.0.0.1:8886 node1
On local: ssh -N -L 8888:127.0.0.1:8887 user#xxx.xxx.xxx.xxx
I think a possible simple solution could be adding an intermediate ssh connection.
Given your workflow is computer -> server (accessing node) -> node1 (computing node), then
From user#remote.node1, execute
jupyter notebook --no-browser --port=8886
From user#remote.server, execute
ssh -N -L localhost:8887:localhost:8886 user#remote.node1
From your computer, execute
ssh -N -L localhost:8888:localhost:8887 user#remote.server
Then run localhost:8888 on your computer browser.
From the resolution of #CasellaJr, perhaps for different servers, you may wish to explicitly change localhost to 127.0.0.1 or [::1] or other addresses that may work.

How to connect to expo via private tunnel (not ngrok)

I have the problem that at work I can not connect via network to expo, so I need to use tunnel, which is fine. However sometimes the tunnel is really slow destroying any developer expierience.
Since I can also host expo locally on localhost I had the idea of simply ssh-tunneling to a remote server that has an open port.
my remote host runs ubuntu
so i SSH there like so:
ssh -R 0.0.0.0:19000:0.0.0.0:19000 user#ip
in order for this to work i also added
GatewayPorts clientspecified
to my /etc/ssh/sshd_config
...
sudo netstat -plutn
shows me
tcp 0 0 0.0.0.0:19000 0.0.0.0:* LISTEN 20183/2
so accepting requests (i also tried to forward port 19001 to get something back when i enter it in the browser which worke fine)
However when i enter:
exp://serverip:19000 into the expo client on my android phone he can't connect.
Any ideas on help?
It looks like Expo uses multiple ports 19000, 19001, and 19002. So you will need to forward all of these.
e.g.
$ ssh -f -N -R 19000:localhost:19000 user#ip
$ ssh -f -N -R 19001:localhost:19001 user#ip
$ ssh -f -N -R 19002:localhost:19002 user#ip
Also, you can set the REACT_NATIVE_PACKAGER_HOSTNAME environment variable to use the remote host.
$ export REACT_NATIVE_PACKAGER_HOSTNAME="ip"
$ expo start

SSH connection to jupyter notebook opens but browser unable to connect

I have a bizarre problem with my SSH connection. I am trying to connect to Ubuntu server from Windows client (local network, Bitvise SSH client).
jupyter notebook --no-browser --port=8885
Everything launches as normal. I then go to my client
ssh -p 2222 -N -f -L 8800:localhost:8885 user#server
Everything seems normal and I get in. I then go my browser and try localhost:8800 and localhost:8885. Neither responds. Any tips would be appreciated. Many thanks.

Connect to Spark running via YARN through a SSH tunnel

I have a Spark installation running under YARN on a remote cluster, with a firewall between me and the head node. I can use a ssh tunnel to access the head node:
> ssh -N -f -L 10000:remotenode:10000 between_machine
and this setup works, for example, to access a HiveServer2 running on remotenote. If Spark was running in cluster mode, I would need to just do the same for the 7077 port and direct the pyspark client to localhost with
> ssh -N -f -L 7077:remotenode:7077 between_machine
> ./pyspark --master spark://localhost:7077
How can I do that with Spark running under the YARN scheduler?
If you are looking for a port to connect, here is a quote from the doc:
You can access this interface by simply opening
http://:4040 in a web browser. If multiple SparkContexts
are running on the same host, they will bind to successive ports
beginning with 4040 (4041, 4042, etc).
If you are just looking for a more universal way to get to the host via ssh "tunnel", you could try ssh working as socks proxy:
ssh user#host -D 20000
And then configuring your browser to connect via socks proxy (host - localhost, port - 20000).

Connect ipython-notebook via SSH tunnel from a remote location

I'm trying to open an ipython-notebook (which is running on a server) on a macbook from a remote location through an ssh tunnel but no data received.
This is the command for the SSH tunnel
ssh -L 5558:localhost:5558 -N -t -x user#remote-host
and this is the command I used to lunch the notebook form the server
ipython notebook --pylab=inline --port=5558 --ip=* --no-browser --notebook-dir notebooks
Than I tried to open it on a new tab with this remote-host:5558 but no data received.
Thanks in advance!
The directive -L AAAA:somehost:BBBB will cause SSH to listen on port AAAA on localhost (the machine the ssh command is run on) and forward any connection to that port, over the SSH session, to the host somehost port BBBB. So, you need to open http://localhost:5558/ in the browser on the machine you run the ssh command on.
Read this: How do I add a kernel on a remote machine in IPython (Jupyter) Notebook?
Remote jupyter kernel/kernels administration utility (the rk) here: https://github.com/korniichuk/rk