How to forward a port with Slurm `srun` without opening another `ssh` on my computer?
Feb 1, 10:34pm
To forward a port using Slurm's srun command without opening another SSH connection from your local machine, you can use Slurm's built-in port forwarding feature. This is especially useful when you want to access a service running on a compute node (e.g., a Jupyter notebook, a web server, or a database) directly from your local browser or application.
Method: Use srun --tunnel (or --forward-port in newer versions)
LOCAL_PORT: The port on your local machine (or login node) that you want to forward.
REMOTE_PORT: The port on the compute node where the service is running.
2. Example: Forwarding a Jupyter Notebook
Suppose you want to forward a Jupyter notebook running on port 8888 on a compute node to your local machine's port 8888:
bash
srun --tunnel=8888:8888 --pty /bin/bash
Once the job starts, launch Jupyter on the compute node:
bash
jupyter notebook --no-browser --port=8888
On your local machine, open a browser and go to:
text
http://localhost:8888
3. Notes
The --tunnel option is available in Slurm 20.11 and later. If you're using an older version, check if your cluster supports it or use alternative methods (like SSH tunneling through the login node).
If you need to forward multiple ports, you can specify multiple --tunnel options: