# SSH tunnelling
## 1-Hop SSH tunnelling
Open a terminal in `Host-A` and run the following:
```bash
ssh user@Host-B -L <port_A>:localhost:<port_B>
```
Next login to `Host-B` and start the Jupyter Notebook or tensorboard as follows:
```bash
jupyter notebook --no-browser --port=<port-B>
tensorboard --logdir=<log-folder> --port=<port-B>
```
Remember, give port number without the brackets `< >`. Next in `Host-A` open browser and go to `localhost:<Port-A>` and then put the jupyter notebook `token` from `Host-B`.
## 2-Hop SSH tunnelling
### Simple steps
1. First open terminal in Host-A and do `ssh` from `Host-A`to `Host-B`
```bash
ssh user@Host-B -L <Port-A>:localhost:<Port-B>
```
1. Now do normal `ssh` to `Host-B` and then from there create ssh tunnel to `Host-C` similarly
```bash
ssh -f user@Host-C -L <Port-B>:localhost:<Port-C>
```
1. Now do normal `ssh` to `Host-C` and start jupyter notebook in `Port-C`.
2. In `Host-A` open browser and go to `localhost:<Port-A>` and then put the jupyter notebook `token` from `Host-C`.
### Compact steps
You can combine the steps 1 and 2 as follows:
```bash
ssh -L <Port-A>:localhost:<Port-B> user@Host-B -t ssh -L <Port-B>:localhost:<Port-C> user@Host-C
```
And then follow steps 3 and 4.
---
## 📚 References
- Mridha, Sankarshan. [‘How to Run Jupyter Notebook in Server Which Is at Multi Hop Distance?’](https://medium.com/@sankarshan7/how-to-run-jupyter-notebook-in-server-which-is-at-multi-hop-distance-a02bc8e78314) _Medium_, 14 June 2018.
- [How to use the tensorboard on a remote server](https://blog.yyliu.net/remote-tensorboard/)