In this note: i) how to tunnel via SSH, ii) mount remote folders and iii) access ipython notebook server running on a remote machine.
SSH tunnel with port forwarding
Often, I run computations on remote computers connecting via SSH.
The problem is that I could not connect directly to private network, so I need to SSH first to a computer available through internet and after to a target computer inside internal network. This setup is very inconvenient, especially when you need to transfer files. Luckily, there is an easy solution that allows you to tunnel you data i.e. SSH port forwarding.
My setup is
HOME_computer ⟶ intermediate_HOST ⟶ target_HOST
To setup forwarding open terminal and run:
ssh -L 3000:target_HOST:22 login_at_intermediate_HOST@intermediate_HOST -N
where
-L stands for port forwarding from target_HOST:22 to localhost:3000 (HOME_computer),
-N for not showing remote shell of login_at_intermediate_HOST@intermediate_HOST.
You can put any available port instead of 3000.
Let it run.
To use the tunnel, open another terminal and type:
ssh -p 3000 login_at_target_HOST@localhost
Mounting remote folders with SSHFS
To mount remote folders, you could use SSHFS (cross-platform, available for Windows, Linux and OS X).
After installing SSHFS, you could mount target_HOST’s user home folder with
sshfs -p 3000 login_at_target_HOST@localhost: /tmp/ssh_mount
I mounted it to the folder /tmp/ssh_mount, which I have created in advance with mkdir /tmp/ssh_mount.
Alternatively, instead of home folder, you could use specified folder with:
sshfs -p 3000 login_at_target_HOST@localhost:**Path/to/folder** /tmp/ssh_mount
Note, you could now use file backup/synchronization software like rsync and unison.
Accessing remote ipython/jupyter notebook via SSH
If you want to run and remotely access jupyter/ipython notebook on target_HOST, then, first, run it with
ipython notebook –no-browser –port=8888
Second, to create another tunnel to access it, on your local machine run (your previously set up tunnel should be running):
ssh -L 9999:localhost:8888 -p 3000 localhost -N
Finally, in your browser, you open
http://localhost:9999,
which shows remote notebook in your browser.
Written: 26/12/2014
Updated: 22/08/2015