Table of Contents


Google Colab is a great service that provides free GPUs (for up to 12hours of continuous usage). It allows users to interact with a sever through a Jupyter notebook environment.

While using Google Colab I encountered few limitations: working with a linear notebook can get messy, no good file editor and also I think Jupyter notebook is not suitable for a structured ML project/code.

In this post I will explain how to transform Google Colab instance into a real server with SSH access (with GPU Nvidia T4) and a directory synchronised with local machine (to edit files/add datasets easily).


The cover summarises steps described hereunder.

Step 1: Start Google Colab and open a Ngrok account

Open the following notebook using your Google account. In addition to that, you will have to create an account on that will be used for port forwarding.

Step 2: Check GPU availability

Run the following code in your notebook to check the GPU availability and nvcc version.

# Check nvidia and nvcc cuda compiler

!/usr/local/cuda/bin/nvcc --version

You should be able to see information about the GPU and nvcc compiler.

Step 3: Mount Google Drive

Now we can link Google drive to Colab using the following script, you’ll be asked to enter an authorization code that could be obtained from the shown link.

# link to google drive

from google.colab import drive

On the other side, on your local host, you can easily download Google drive application and choose a folder to be synchronised between you laptop and google drive. Let us call it ssh_files. So up to now, ssh_files folder is available on Google drive, synchronised with your machine and mounted on Colab in the following path

#check that Gdrive is mounted on Colab
!ls '/content/gdrive/My Drive/ssh_files/'

This step can be omitted if we chose to work with Github and use it to keep track of modifications and synchronise.

Step 4: Setup SSH forwarding

Next step consists on using Ngrok to make ssh forwarding. We first generate a user name and a password on Google Colab and start sshd (refer to the Notebook for code details).

After that, we can easily download Ngrok, get auth key and run it. This will create a TCP tunnel.

# 2 - Download Ngrok

! wget -q -c -nc
! unzip -qq -n

# 3 - setup Ngrok - authtoken

#Ask token
print("Get your authtoken from")
import getpass
authtoken = getpass.getpass()

#Create tunnel
get_ipython().system_raw('./ngrok authtoken $authtoken && ./ngrok tcp 22 &')

After this step, if you go to you’ll be able to see something like this

URL: tcp://

Client IP: ***.***.***.***

Region: us

Established: May 17th, 2019 08:44:18 UTC


Now you can enjoy your server through ssh, connect to it simply using

# -p : the port is the same as the one shown in Ngrok status
ssh [email protected] -p 16568
> enter the password generated at the beginning of step 4
# if nvidia-smi is not working try: export LD_PRELOAD=/usr/lib64-nvidia/
Jetson Screen

You can code locally in the directory synchronised with Google drive and execute it on the instance you’re connected to through ssh forwarding.

In next blog posts, I’ll use this setup to train a simple Machine Learning model and deploy it on Jetson Nano (Setup Jetson Nano blog post ).

👻 Bonus 👻

You can even run a JupyterLab from the instance and forward it to a public URL. Run the following commands after you get connected to the instance via Ngrok.

#install tmux and jupyter lab
sudo apt-get install tmux
pip install jupyter lab

# open a tmux session and launch jupyterlab
jupyter lab --ip --no-browser --allow-root

# make a split in the same session: ctrl+b then "
# create tunnel supposing that jupyter is running on
# change 'myjupyter-lab' to whatever you like
ssh -R myjupyter-lab:80:localhost:8888

In your browser go to and enjoy full functionalities of JupyterLab from a Google Colab instance.