https://github.com/lamhoangtung/colab_ssh
Create SSH tunel to a running colab notebook
https://github.com/lamhoangtung/colab_ssh
colab ssh
Last synced: about 1 year ago
JSON representation
Create SSH tunel to a running colab notebook
- Host: GitHub
- URL: https://github.com/lamhoangtung/colab_ssh
- Owner: lamhoangtung
- License: mit
- Created: 2020-11-30T04:29:04.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-10-12T03:58:20.000Z (almost 5 years ago)
- Last Synced: 2025-06-22T04:41:10.868Z (about 1 year ago)
- Topics: colab, ssh
- Language: Python
- Homepage: https://pypi.org/project/linus-colab-ssh/
- Size: 133 KB
- Stars: 67
- Watchers: 1
- Forks: 16
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Colab SSH
Create SSH tunel to a running colab notebook
[](https://badge.fury.io/py/linus-colab-ssh)
[](https://pepy.tech/project/linus-colab-ssh)

[](https://codecov.io/gh/Techainer/mlchain-python)
[](https://github.com/lamhoangtung/colab_ssh/blob/master/LICENSE)
## Prerequisite
- This package only allow SSH public key authentication so you will need to prepare once. You might already had one at `~/.ssh/id_rsa.pub`. Refer [this](https://www.digitalocean.com/community/tutorials/how-to-configure-ssh-key-based-authentication-on-a-linux-server) to create a new one if you don't had once already
- In order to connect to the SSH tunel from your machine, you will need to install `cloudflared` from [here](https://developers.cloudflare.com/argo-tunnel/downloads)
## Usage
Create a new Colab notebook with a single cell with the following content:
```python
!pip3 install linus-colab-ssh
from colab_ssh import setup_ssh, loop_forever
public_key = ''
setup_ssh(public_key)
loop_forever()
```
You can use list of public key or link to a raw text file of `authorized_keys` like [this](https://gist.githubusercontent.com/lamhoangtung/4fca574da11ef45869bdfea8062417b5/raw/320893c60a5a150f61481899201664761136fae7/authorized_keys) as well
Optinally, you can also specify a Mattermost Webhook URL with `mattermost_webhook_address` when calling `setup_ssh` to send a push notification to your Mattermost channel when the SSH tunel is ready.
Run it, after about 2 minutes, you will see something like this:
```bash
Command to connect to the ssh server:
✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️
ssh -o UserKnownHostsFile=/dev/null -o VisualHostKey=yes -oProxyCommand="cloudflared access ssh --hostname %h" root@economic-singapore-place-obtaining.trycloudflare.com
✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️
Or you can use the following configuration in your .ssh/config file:
✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️
Host colab
HostName economic-singapore-place-obtaining.trycloudflare.com
User root
UserKnownHostsFile /dev/null
VisualHostKey yes
StrictHostKeyChecking no
ProxyCommand cloudflared access ssh --hostname %h
✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️✂️```
```
Then voila ;)
Please noted that you must keep the kernel webpage connected to avoid Colab disconnect your kernel early.
## Disclaimer
This repo contains many of the configuration that I use for my day to day work so it might not be the best for you.
If you had any problems using this, feel free to open an issue. Otherwise, I highly recommend you to fork this repo and did some necessary modification for yourself. Thanks for checking by