Skip to content

Instantly share code, notes, and snippets.

@ahmedengu
Last active May 9, 2025 01:33
Show Gist options
  • Select an option

  • Save ahmedengu/9c04165fc303aebc8a5a2360234b28bf to your computer and use it in GitHub Desktop.

Select an option

Save ahmedengu/9c04165fc303aebc8a5a2360234b28bf to your computer and use it in GitHub Desktop.
Use google colab as a remote machine with the help of ngrok, vnc server and xface desktop you can change the configurations and desktop environment as you please it's just a start
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "colab_xface_vnc",
"version": "0.3.2",
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/ahmedengu/9c04165fc303aebc8a5a2360234b28bf/colab_xface_vnc.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"metadata": {
"id": "jPXzrd3sbE8I",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"* Enable colab GPU\n",
"* Set ngrok auth below\n",
"* Run all"
]
},
{
"metadata": {
"id": "Uys7SO6pOod_",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 217
},
"outputId": "56b71ba8-af90-4b4b-dbe3-dbbe2db3d716"
},
"cell_type": "code",
"source": [
"# install xface\n",
"!apt install xfce4 xfce4-goodies\n",
"# install vnc server\n",
"!apt install vnc4server\n",
"# install ngrok\n",
"! wget -q -c -nc https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip\n",
"! unzip -qq -n ngrok-stable-linux-amd64.zip\n",
"\n",
"# configure\n",
"!printf \"#!/bin/bash\\nstartxfce4 &\" > ~/.vnc/xstartup\n",
"!chmod +x ~/.vnc/xstartup"
],
"execution_count": 4,
"outputs": [
{
"output_type": "stream",
"text": [
"Reading package lists... Done\n",
"Building dependency tree \n",
"Reading state information... Done\n",
"xfce4 is already the newest version (4.12.4).\n",
"xfce4-goodies is already the newest version (4.12.4).\n",
"0 upgraded, 0 newly installed, 0 to remove and 10 not upgraded.\n",
"Reading package lists... Done\n",
"Building dependency tree \n",
"Reading state information... Done\n",
"vnc4server is already the newest version (4.1.1+xorg4.3.0-37.3ubuntu2).\n",
"0 upgraded, 0 newly installed, 0 to remove and 10 not upgraded.\n"
],
"name": "stdout"
}
]
},
{
"metadata": {
"id": "GUcnbVDyPbU4",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 54
},
"outputId": "f6f7037f-9037-4615-81dc-ca7dfe491575"
},
"cell_type": "code",
"source": [
"# set the password, max 8 chars\n",
"!vncpasswd"
],
"execution_count": 5,
"outputs": [
{
"output_type": "stream",
"text": [
"Password:\n",
"Verify:\n"
],
"name": "stdout"
}
]
},
{
"metadata": {
"id": "J9tPozpmRf2l",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 318
},
"outputId": "07e1e138-d3f1-4566-da29-47a8efe5e821"
},
"cell_type": "code",
"source": [
"# set ngrok auth and run forever\n",
"NGROK_AUTH = \"\"\n",
"VNC_PORT = 5901\n",
"\n",
"from time import sleep\n",
"from IPython.display import clear_output\n",
"import requests\n",
"import json\n",
"\n",
"# keep everything running\n",
"i=0\n",
"while True:\n",
" try:\n",
" # start vnc server\n",
" if len(get_ipython().getoutput('ps -ef | grep vnc')) <= 2:\n",
" get_ipython().system_raw('vnc4server -httpport $VNC_PORT &')\n",
" sleep(5)\n",
" \n",
" ngrok_link = json.loads(requests.get('http://localhost:4040/api/tunnels').text)['tunnels'][0]['public_url']\n",
" print(ngrok_link)\n",
" sleep(30)\n",
" requests.get(ngrok_link)\n",
" except (KeyboardInterrupt, SystemExit):\n",
" raise\n",
" except:\n",
" # create ngrok port\n",
" get_ipython().system_raw('./ngrok authtoken $NGROK_AUTH && ./ngrok tcp $VNC_PORT &')\n",
" i+=1\n",
" if i >=5:\n",
" clear_output(wait=True)\n",
" i=0\n"
],
"execution_count": 6,
"outputs": [
{
"output_type": "stream",
"text": [
"tcp://0.tcp.ngrok.io:10721\n",
"tcp://0.tcp.ngrok.io:10721\n",
"tcp://0.tcp.ngrok.io:10721\n"
],
"name": "stdout"
},
{
"output_type": "error",
"ename": "KeyboardInterrupt",
"evalue": "ignored",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-6-a9abdbc36a9f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 18\u001b[0m \u001b[0mngrok_link\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mjson\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloads\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrequests\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'http://localhost:4040/api/tunnels'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'tunnels'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'public_url'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 19\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mngrok_link\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 20\u001b[0;31m \u001b[0msleep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m30\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 21\u001b[0m \u001b[0mrequests\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mngrok_link\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 22\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mKeyboardInterrupt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mSystemExit\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
]
}
]
}
]
}
@bargeamol2000
Copy link
Copy Markdown

how to access remote desktop

@Kief5555
Copy link
Copy Markdown

Kief5555 commented Mar 7, 2022

how to access remote desktop

Learn Linux. You can use terminal, cmd, or powershell.

@bargeamol2000
Copy link
Copy Markdown

thanks

@thearthouse
Copy link
Copy Markdown

web browser and terminal not working

@wfq1971
Copy link
Copy Markdown

wfq1971 commented May 9, 2025

can't run on cpu?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment