bmabir17 / Colab-SSH-and-GDrive

SSH into Colab notebook with access to your google drive.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Colab-SSH-and-GDrive

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.

Steps

  1. Create your free account at ngrok and get the authtoken. This will be used in Step4.
    Should look like $ ./ngrok authtoken ZT64bWYnXsdTAdfdassJej42auAQqKqZHn2Sh4g2sfAD
  2. Get the public key of your local machine.
    $ ssh-keygen
    $ cat .ssh/id_rsa.pub
  3. Go to your colab notebook. Copy the content from template provided above (ssh_colab.ipynb).
  4. 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.
  5. Now you should get output something like ssh root@0.tcp.ngrok.io -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/

Screenshot


Extra:

Steps for running a JupyterLab instance on top of it:

  1. Execute the following commands:
    apt-get install tmux && pip install jupyter lab
    tmux
    jupyter lab --ip 0.0.0.0 --port 56784
  2. Split the same terminal: Ctrl+b & Shift+"
  3. Execute ssh -R 80:localhost:56784 something@ssh.localhost.run
    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!

Screenshot
Screenshot
Screenshot


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

About

SSH into Colab notebook with access to your google drive.


Languages

Language:Jupyter Notebook 100.0%