demotomohiro / remocolab

remocolab is a Python module to allow remote access to Google Colaboratory using SSH or TurboVNC.
MIT License
316 stars 229 forks source link

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.

Requirements

If you use ngrok:

If you use Argo Tunnel:

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()

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.

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()

Experimental kaggle support

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
  1. Follow instructions from step 4 in above "How to use".