Nageen Chand
Nageen Chand Author of this blog
Posted on: Post a comment

Guide to connect to google colab with ssh from terminal and run jupyter lab

Guide to connect to google colab with ssh from terminal and run jupyter lab

Google colab is a good option to experiment and try heavy computational tasks on a high end computer for free. Notebook interface provided by google is perfect python programs.

I have made a script to connect to colab instance with just few comands.

What you need ?

  1. ngrok Account

  2. ssh public key

Go to and create an account and copy the authtoken only

./ngrok authtoken ZT64bWYnXsdTAdfdassJej4FNFT_2auAQqKqZHn2Sh4g2sfAD 

we need only last argument of command from above.

for second option : run ssh-keygen and just press enter 3–4 times if it asks for anything

and then copy the public key

run cat .ssh/

reference is here

now open google colab, connect to desired runtime type and execute following commands in notebook cell:

! wget


Enter the authtoken and ssh public key when prompt asks respectively.

it will print the ssh command to connect to colab instance. e.g

ssh -p 16826 # it will be different for your case

Open terminal in your local pc and run the command you get on colab.

you will get a bash shell logged in to colab instance. for jupyterlab, first install following on the terminal :

pip3 install jupyterlab && apt install tmux

now run tmux and run following command in it: (chose port of your choice {I prefer 5 digit random number})

jupyter lab --ip --port 56784

now press ctrl + b and then “ to split split window and then run follow in new window: (use the same port you used for jupyter lab)

ssh -R 80:localhost:56784 

You should get a URL after this on terminal open this in browser and you should get your jupyter lab on browser connected to google colab instance.

To minimize tmux on terminal, press ctrl+b and then d.

Script used :

For any query/doubt or correction, please comment below.

Also read this post at : here