Skip to content

Instantly share code, notes, and snippets.

@sveitser
Last active August 27, 2021 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sveitser/95af33c4c549d42a4233db443e5d6cec to your computer and use it in GitHub Desktop.
Save sveitser/95af33c4c549d42a4233db443e5d6cec to your computer and use it in GitHub Desktop.
SSH into colab, use vscode remote extension

Using Editor or IDE with colab

Note: worked in 2020, may no longer work exactly as described.

Idea: conveniently work with github repo and notebook on colab.

  1. Sign up for ngrok
  2. Install colab_ssh in colab notebook
  3. Start tunnel
    1. Provide ngrok token from https://dashboard.ngrok.com/auth/your-authtoken
      1. Can this be hidden? We could put it into google drive and fetch it from there.
    2. Take note of config printed to notebook
  4. Connect vscode
    1. Option 1: run vscode on colab, connect via browser
      • Setup
        1. connect from local machine

          ssh -A -L 9999:localhost:9999 root@2.tcp.ngrok.io -p 10865
          apt install tmux
          tmux
          git config --global user.name my_name
          git config --global user.name my_email
          code-server --bind-addr 127.0.0.1:9999 --auth none
        2. Go to http://localhost:9999 in browser

      • Settings made persistent by saving them in google drive
    2. Option 2: run vscode locally, connect via remote extension
      • Setup
        1. Put the this into ~/.ssh/config (replace with values shown in colab)

          Host google_colab_ssh
                  ForwardAgent yes
          	HostName 2.tcp.ngrok.io
          	User root
          	Port 10865
        2. Install vscode locally

        3. Install remote ssh extenstion

        4. Command + P connect to host

        5. Select google_colab_ssh

      • Are settings persistent?
      • Where are extensions installed?
        • Seems they are also installed on remote.
          • Probably in /root/.vscode-server
        • How to save in drive?
          • Symlink like with other solution
  5. in vscode
    1. Install python extension
      1. Current (August 4, 2020) version is broken (at least for vscode remote server with browser), so downgrade to 2020.5.86806
    2. Install git lens
    3. Repo level config
      1. Configure black as formatter
      2. Turn on save on formatting
      3. Python path
      4. flake8 as linter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment