• This repository has been archived on 15/Sep/2022
  • Stars
    star
    310
  • Rank 134,926 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created over 5 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

remocolab is a Python module to allow remote access to Google Colaboratory using SSH or TurboVNC.

remocolab

Using a remote desktop or SSH is now disallowed from Colab runtimes

remocolab is a Python module to allow remote access to Google Colaboratory using SSH or TurboVNC. It also install VirtualGL so that you can run OpenGL programs on a Google Colaboratory machine and see the screen on VNC client. It secures TurboVNC connection using SSH port forwarding.

How to access SSH server running in colab?

ngrok currently doesn't work! ngrok works now

You cannot directory login to the SSH server running on a colab instace. remocolab uses third party service to access it from your PC. You can choose ngrok or Argo Tunnel. You don't need to buy paid plan. Which service works faster can depend on where/when you are.

  • ngrok
    • require that you sign up for an account.
    • You don't need to install specific software on client machine.
    • You need to copy and paste authtoken to colab everytime you run remocolab.
  • Argo Tunnel
    • You don't need to create account. Cloudflare provide free version
    • You need to copy cloudflared on your client PC.
    • You cannot specify argo tunnel server's region. They says the connection uses Argo Smart Routing technology to find the most performant path.

Requirements

If you use ngrok:

  • ngrok Tunnel Authtoken
  • You need to sign up for ngrok to get it

If you use Argo Tunnel:

  • Download cloudflared on your client PC and untar/unzip it.

How to use

  1. (Optional) Generate ssh authentication key
    • By using public key authentication, you can login to ssh server without copy&pasting a password.
    • example command to generate it with ssh-keygen:
    ssh-keygen -t ecdsa -b 521
  2. Create a new notebook on Google Colaboratory
  3. Add a code cell and copy & paste one of following codes to the cell
    • If you use public key authentication, specify content of your public key to public_key argument of remocolab.setupSSHD() or remocolab.setupVNC() like remocolab.setupSSHD(public_key = "ecdsa-sha2-nistp521 AAA...")
    • add tunnel = "ngrok" if you use ngrok.
  • SSH only:
!pip install git+https://github.com/demotomohiro/remocolab.git
import remocolab
remocolab.setupSSHD()
  • SSH and TurboVNC:
!pip install git+https://github.com/demotomohiro/remocolab.git
import remocolab
remocolab.setupVNC()
  1. (Optional) If you want to run OpenGL applications or any programs that use GPU, Click "Runtime" -> "Change runtime type" in top menu and change Hardware accelerator to GPU.
  2. Run that cell
  3. (ngrok only)Then the message that ask you to copy & paste tunnel authtoken of ngrok will appear. Login to ngrok, click Auth on left side menu, click Copy, return to Google Colaboratory, paste it to the text box under the message and push enter key.
    • ngrok token must be kept secret. I understand people hate copy & pasting ngrok token everytime they use remocolab, but I don't know how to skip it without risking a security. If you could specify ngrok token to remocolab.setupSSHD() or remocolab.setupVNC(), you can save ngrok token to a notebook. Then, you might forget that your notebook contains it and share the notebook.
  4. (ngrok only)Select your ngrok region. Select the one closest to your location. For example, if you were in Japan, type jp and push enter key.
    • You can also specify ngrok region to remocolab.setupSSHD() or remocolab.setupVNC() in the code like remocolab.setupSSHD(ngrok_region = "jp").
  5. remocolab setup ngrok and SSH server (and desktop environment and TurboVNC server if you run setupVNC). Please wait for it done
    • remocolab.setupSSHD() takes about 2 minutes
    • remocolab.setupVNC() takes about 5 minutes
  6. Then, root and colab user password and ssh command to connect the server will appear.
  7. Copy & paste that ssh command to your terminal on your local machine and login to the server.
    • use displayed colab user's password if you dont use public key authentication
    • Even if you just want to use TurboVNC, you need to login using SSH to make SSH port forwarding
  • If you use TurboVNC:
  1. Run TurboVNC viewer on your local machine, set server address to localhost:1 and connect.
  2. Then, password will be asked. Copy & paste the VNC password displayed in remocolab.setupVNC()'s output to your TurboVNC viewer.

When you got error and want to rerun remocolab.setupVNC() or remocolab.setupSSHD(), you need to do factory reset runtime before rerun the command. As you can run only 1 ngrok process with free ngrok account, running remocolab.setupVNC/setupSSHD will fail if there is another instace that already ran remocolab. In that case, terminate another instance from Manage sessions screen.

How to run OpenGL applications

Put the command to run the OpenGL application after vglrun. For example, vglrun firefox runs firefox and you can watch web sites using WebGL with hardware acceleration.

How to mount Google Drive

remocolab can allow colab user reading/writing files on Google Drive. If you just mount drive on Google Colaboratory, only root can access it.

Click the folder icon on left side of Google Colaboratory and click mount Drive icon. If you got new code cell that contains python code "from google.colab import ...", create a new notebook, copy your code to it and mount drive same way. On new notebook, you can mount drive without getting such code cell.

  • You can still mount google drive by clicking the given code cell, but it requres getting authorization code and copy&pasting it everytime you run your notebook.
  • If you mount google drive on new notebook, it automatically mount when your notebook connect to the instance.

Add mount_gdrive_to argument with directory name to remocolab.setupSSHD() or remocolab.setupVNC(). For example:

  remocolab.setupSSHD(mount_gdrive_to = "drive")

Then, you can access the content of your drive in /home/colab/drive. You can also mount specific directory on your drive under colab user's home directory. For example:

  remocolab.setupSSHD(mount_gdrive_to = "drive", mount_gdrive_from = "My Drive/somedir")

Arguments of remocolab.setupSSHD() and remocolab.setupVNC()

  • ngrok_region Specify ngrok region like "us", "eu", "ap". List of region. This argument is ignored if you specified tunnel = "argotunnel".
  • check_gpu_available When it is True, it checks whether GPU is available and show warning in case GPU is not available.
  • tunnel Specify which service you use to access ssh server on colab. It must be "ngrok" or "argotunnel". default value is "argotunnel".
  • mount_gdrive_to Specify a directory under colab user's home directory which is used to mount Google Drive. If it was not specified, Google Drive is not mount under colab user's home directory. Specifying it without mounting Google Drive on Google Colaboratory is error.
  • mount_gdrive_from Specify a path of existing directory on your Google Drive which is mounted on the directory specified by mount_gdrive_to. This argument is ignored when mount_gdrive_to was not specified.
  • public_key Specify ssh public key if you want to use public key authentication.

How to setup public key authentication for root login

If you want to login as root, use following code:

!mkdir /root/.ssh
with open("/root/.ssh/authorized_keys", 'w') as f:
  f.write("my public key")
!chmod 700 /root/.ssh
!chmod 600 /root/.ssh/authorized_keys

And replace user name colab in ssh command to root.

Experimental kaggle support

  • As Kaggle stops sesson right after running ssh server, kaggle is no longer supported.

remocolab in kaggle branch works on Kaggle.

  1. Create a new Notebook with Python language.
  2. Set settings to:
    • Internet on
    • Docker to Latest Available
    • GPU on if you use TurboVNC
  3. Add a code cell and copy & paste one of following codes to the cell
  • SSH only:
!pip install git+https://github.com/demotomohiro/remocolab.git@kaggle
import remocolab
remocolab.setupSSHD()
  • SSH and TurboVNC:
!pip install git+https://github.com/demotomohiro/remocolab.git@kaggle
import remocolab
remocolab.setupVNC()
  1. Follow instructions from step 4 in above "How to use".

More Repositories

1

nim4colab

Nim4Colab is a IPython extension to use Nim language on Google Colaboratory.
Python
26
star
2

nim-4k-intro-sample

4k intro sample code written with Nim programming language.
Nim
12
star
3

littlesugar

Nim macros that might help writing simpler and safer code.
Nim
9
star
4

nim-de-blog

Nim De Blog is a static site generater that uses Nim programming language.
Nim
7
star
5

Reflection-Refraction-less-Ronpa-Raytracing-Renderer

レイトレ合宿3!!!で公開したレンダラ
C++
6
star
6

pathX

Generic path handling library
Nim
4
star
7

glew4kb

Automate OpenGL extension initialization for 4k intro.
C++
4
star
8

Falsity-of-employment

正式名称は"雇用の欺瞞"です。 Tokyo Demo Fest 2014で公開した4k introのソースコードです。
C++
3
star
9

Google-Colaboratory-SSH-samples

Sample code to access Google Colaboratory using SSH.
Jupyter Notebook
3
star
10

divmath

Math library related to integer division for Nim language
Nim
3
star
11

Internet-of-Tomohiro

My blog site
Nim
2
star
12

rcauto

レイトレ合宿における作品を自動実行するやつ
Python
2
star
13

demotomohiro.github.com

HTML
2
star
14

nimopenjtalk

Open JTalk and hts_engine API bindings for Nim
C++
2
star
15

netlify-nim-test

Try using nim compiler on netlify
Nim
2
star
16

Loremo

Loremo is a neovim plugin to help using neovim inside neovim by adding local/remote mode to each window displaying terminal buffer.
Vim Script
1
star
17

winlean4k

Windows API for making 4k intro with Nim programming language
Nim
1
star
18

kokocandy

Automatic demo video downloading and converting script
Vim Script
1
star
19

hidecmakelinker

Tool and library to use C/C++ libraries using CMake from Nim programming language
Nim
1
star
20

The-Job-changing-knight-Ganglion

転職騎士ガングリオン。Tokyo Demo Fest 2015で公開したPC 8k introです。
C++
1
star
21

MinimumNimPico

Minimum program runs on Raspberry Pi Pico written in Nim
Nim
1
star