A convenient way to utilize Colab GPUs and save the progress from your local Terminal. SSH into Colab notebook with access to your google drive.
- Create your free account at ngrok and get the authtoken. This will be used in Step4.
Should look like$ ./ngrok authtoken ZT64bWYnXsdTAdfdassJej42auAQqKqZHn2Sh4g2sfAD
- Get the public key of your local machine.
$ ssh-keygen
$ cat .ssh/id_rsa.pub
- Go to your colab notebook. Copy the content from template provided above (ssh_colab.ipynb).
- Execute the colab notebook. Mount your Google Drive. When prompted, enter the authtoken obtained in Step1. Lastly, it will ask the public key of your local machine obtained in Step2.
- Now you should get output something like
ssh [email protected] -p 12**6
. The port will be different for your case. Go to your local machine and run this ssh command. Done!
By default, you will be inside a temporary space and its content will be deleted once your Colab session ends. If you want to save your work, you should explicitly save your changes in the mounted google drive.
Your Google Drive files will be present in /content/gdrive/My Drive/
- Execute the following commands:
apt-get install tmux && pip install jupyter lab
tmux
jupyter lab --ip 0.0.0.0 --port 56784
- Split the same terminal: Ctrl+b & Shift+"
- Execute
ssh -R 80:localhost:56784 [email protected]
You should get an output like this:
Connect to http://something-caa4e22c.localhost.run or https://something-caa4e22c.localhost.run
Connect to this url in your PC browser. Done!
References:
1. https://imadelhanafi.com/posts/google_colal_server/
2. https://medium.com/@archie9211/guide-to-connect-to-google-colab-with-ssh-from-terminal-and-run-jupyter-lab-7ed60258368