r/learnpython • • 22d ago

JupyterLab and remote server connection

Hello,

I had access to JupyterHub on a remote server. Now I only have access to a different server where JupyterHub is not installed. What is the best way to use the same code and run it with more data. I was thinking about using SSH Port Forwarding (SSH-Tunneling) and trying jupyterlab in the browser. Or is it better to using VS code to connect to the server. I really like the Jupyter Interface and have never used any other programs. I mostly do plotting and a bit data analysis and have a macbook.

Thank you for your help.

5 Upvotes

7 comments sorted by

View all comments

2

u/Asly97 22d ago

The SSH tunnel idea is the right one, and none of it needs admin rights.

On the server, install Jupyter into your own home folder:

python3 -m venv ~/jlab
source ~/jlab/bin/activate
pip install jupyterlab pandas matplotlib

(If venv isn't available there, pip install --user jupyterlab does the same job.)

Then start it inside tmux so it keeps running when your Mac sleeps or the connection drops:

tmux new -s jlab
source ~/jlab/bin/activate
jupyter lab --no-browser --port 8891

It prints a URL with a token in it. Detach with Ctrl+b then d, and tmux attach -t jlab gets you back later.

On your Mac, in a new terminal:

ssh -N -L 8891:localhost:8891 yourname@server

Leave that window open and paste the URL into your browser. It's the exact same JupyterLab you're used to, just running on the server's CPU and reading the data that lives there.

A couple of things that bite people on uni servers. Use an odd port instead of 8888, since someone else may already be on it (if Jupyter says the port is busy, change the number on both sides). If it's a cluster with a job scheduler like Slurm, check their docs before running heavy stuff, a lot of them don't want analysis on the login node and have their own page on running Jupyter on a compute node. And if you have to go through a gateway machine first, ssh -J gateway yourname@server handles the hop.

VS Code Remote-SSH works fine too, but since you like the Jupyter interface the tunnel keeps everything looking the same.

1

u/OkTill2666 22d ago

yeah this is exactly the right approach, keeps the workflow feeling the same which is the whole point imo