Do like to access the Google Colaboratory directly from your machine? Running your script via terminal and having shell access? Then there is a good news, just do the followings:
SSH to Google Colaboratory
1. Install colab_ssh
on Google Colaboratory
1 |
!pip install colab_ssh --upgrade |
Add cloudflared
and password for root user:
1 2 |
from colab_ssh import launch_ssh_cloudflared, init_git_cloudflared launch_ssh_cloudflared(password="<PUT_YOUR_PASSWORD_HERE>") |
2. Install cloudflared on your machine
Downlaod it from here
1 2 |
wget -q https://bin.equinox.io/c/VdrWdbjqyF/cloudflared-stable-linux-amd64.deb dpkg -i cloudflared-stable-linux-amd64.deb |
3. Append the following to your SSH config file (the file is in ~/.ssh/config)
1 2 3 4 5 |
Host *.trycloudflare.com HostName %h User root Port 22 ProxyCommand /usr/local/bin/cloudflared access ssh --hostname %h |
4. To connect using your terminal, type this command:
1 |
ssh witness-atmospheric-structure-kinds.trycloudflare.com |
The followings are optional if you want to install Anaconda /Pytorch
5. Installing Anaconda on Google Colaboratory machine
Prerequisite:
1 |
apt-get install libgl1-mesa-glx libegl1-mesa libxrandr2 libxrandr2 libxss1 libxcursor1 libxcomposite1 libasound2 libxi6 libxtst6 |
Download Anaconda, install it and add it to the path:
1 2 3 |
wget https://repo.anaconda.com/archive/Anaconda3-2020.11-Linux-x86_64.sh bash Anaconda3-2020.11-Linux-x86_64.sh export PATH="/root/anaconda3/bin:$PATH" |
Refs: [1]
Accessing Google Drive in Google Colaboratory
You can access files with:
1. Mounting Google Drive
1 2 |
from google.colab import drive drive.mount('/content/drive') |
Visit the URL in a browser and enter your authorization code
Your drive will be mounted on:
Mounted at /content/drive
You can access your drive in your Jupiter notebook:
1 |
!ls /content/drive |
via python code:
1 2 3 4 5 |
root='/content/drive' import os for path, subdirs, files in os.walk(root): for name in files: print(os.path.join(path, name)) |
2. Using PyDrive
1 2 3 4 |
from pydrive.auth import GoogleAuth from pydrive.drive import GoogleDrive from google.colab import auth from oauth2client.client import GoogleCredentials |
Authenticate and create the PyDrive client:
1 2 3 4 |
auth.authenticate_user() gauth = GoogleAuth() gauth.credentials = GoogleCredentials.get_application_default() drive = GoogleDrive(gauth) |
Access your files:
1 2 3 |
file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList() for file1 in file_list: print('title: %s, id: %s' % (file1['title'], file1['id'])) |
To prevent Google Colab from disconnecting, Just create a new cell at the bottom having the following line:
1 |
while True:pass |