YouMind
Sign in

How to Use Google Colab as a Remote SSH Server

@jandisufg
PORTUGUESENov 19, 2026
206K
1.8K
97
40
3.6K

TL;DR

This tutorial explains how to use the official Google Colab CLI to establish SSH connections, turning Colab instances into remote servers. It details installation, configuration, authentication, and best practices for managing compute resources and data persistence.

Google Colab is not just a notebook. With the official Google CLI, google-colab-cli, you can open an SSH terminal on a Colab machine, with or without GPU, directly from your terminal, VS Code, or any editor that speaks SSH.

In this article: install the CLI, configure ~/.ssh/config, perform the first login, and connect/disconnect without wasting compute units.

What You Need

  • A Google account with access to Colab (Google AI Subscription - Plus, Pro, or Ultra)
  • Python 3 with uv or pip
  • OpenSSH, which comes pre-installed on Linux, macOS, and Windows 10/11
  • An ed25519 SSH key

1. Install the Colab CLI

The official package is called google-colab-cli and installs the colab command.

text
1uv tool install google-colab-cli
2# or: pip install google-colab-cli
3colab version
Janderson F. | elyra.sh - inline image

2. Have an SSH Key

When connecting, colab sends your public key to the machine. By default, it looks for ~/.ssh/id_ed25519.pub or id_ecdsa.pub. Don't have one yet?

text
1ssh-keygen -t ed25519

Using a key with a different name? No problem: you point to it in the next step using -i.

3. Add the Host to ~/.ssh/config

Open (or create) the ~/.ssh/config file and paste this block:

text
1Host colab
2 User root
3 ProxyCommand colab ssh --proxy-mode -s colab -i ~/.ssh/id_ed25519.pub
4 StrictHostKeyChecking no
5 UserKnownHostsFile /dev/null
Janderson F. | elyra.sh - inline image

What each line does:

  • Host colab: The nickname. After this, just type ssh colab.
  • ProxyCommand: Instead of opening a connection to an IP, SSH talks to colab ssh --proxy-mode, which bridges to the Colab machine. The -s colab is the session name: if it doesn't exist, the CLI creates it.
  • StrictHostKeyChecking no and UserKnownHostsFile /dev/null: Each session is a new machine with a new host key. Without this, SSH complains at every connection.

Two pitfalls that cost me time:

  • If your config has a Host block, place colab before it. In SSH, the first value found is the one that counts: a `StrictHostKeyChecking no` under `Host ` above overrides the one for colab.
  • On Windows, use the absolute path for the key in -i (C:/Users/you/.ssh/id_ed25519.pub). The ~ inside the ProxyCommand is not expanded.

4. Perform the First Login in a Real Terminal

The first time, the CLI asks for authorization from your Google account: it shows a link, you approve it in the browser, and paste back the code displayed by Google.

text
1colab new -s colab
Janderson F. | elyra.sh - inline image

Attention: Do this first login in an interactive terminal (PowerShell, Terminal, iTerm). If the first ssh colab comes from something without a keyboard, like an AI agent, a script, or a command triggered from within a chat, the CLI has nowhere to read the code and the login fails with "Malformed auth code". Once the login is saved, anywhere works.

Want GPU? Create the session with it already: colab new -s colab --gpu T4. It also accepts L4, A100, and H100, and --high-mem for more RAM.

5. Connect

text
1ssh colab
Janderson F. | elyra.sh - inline image

You land as root in /content, on Ubuntu 24.04. The non-GPU session in the screenshot has 2 vCPUs, 12 GB of RAM, and about 226 GB of disk.

You can also run a single command without opening the shell:

text
1ssh colab "nvidia-smi"

And since it's standard SSH, VS Code (Remote - SSH), scp, rsync, and any editor with remote machine support see the colab host without extra configuration.

6. Shut Down When Finished

The session consumes compute units while powered on, even if idle. Done? Stop it and check:

text
1colab stop -s colab
2colab sessions
3colab usage
Janderson F. | elyra.sh - inline image

To avoid relying on memory, the CLI has --rm, which stops the session when SSH closes. Just add it to the ProxyCommand:

text
1ProxyCommand colab ssh --proxy-mode -s colab --rm -i ~/.ssh/id_ed25519.pub

Duration and Cost

  • Each machine type consumes units at its own rate. Non-GPU is almost nothing; T4 runs around 1.8 per hour, L4 at 4.8, and A100 at 11 to 13. Values change: check with colab usage while the session is on.
  • Sessions have a time cap (up to about 24 h on Pro) and drop due to inactivity.
  • Disk is disposable. When the session ends, everything disappears. Git push or copy your files before (scp, rsync, or colab download), or mount Google Drive with colab drivemount.

CLI Commands Worth Memorizing

  • colab sessions: Lists active sessions
  • colab status: Session state
  • colab usage: Balance and usage rate
  • colab upload / colab download: Send and fetch files
  • colab drivemount: Mounts Google Drive on the machine
  • colab stop -s <name>: Stops the session

Done: Colab becomes just another host in your ~/.ssh/config. One ssh colab and you're on a Linux machine with GPU, paying only for the time it stays on.

One-click save

Use YouMind for AI deep reading of viral articles

Save the source, ask focused questions, summarize the argument, and turn a viral article into reusable notes in one AI workspace.

Explore YouMind
For creators

Turn your Markdown into a clean 𝕏 article

When you publish your own long-form writing, images, tables, and code blocks make 𝕏 formatting painful. YouMind turns a full Markdown draft into a clean, ready-to-post 𝕏 article.

Try Markdown to 𝕏

More patterns to decode

Recent viral articles

Explore more viral articles