Created
February 9, 2024 19:40
-
-
Save afvanwoudenberg/904ae132a578fb61f8bd1149b0dc6b53 to your computer and use it in GitHub Desktop.
Get shell access to the Google Colab runtime on a free Colab plan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "l2wkWIGf9UFT" | |
}, | |
"source": [ | |
"# Terminal\n", | |
"\n", | |
"Aswin van Woudenberg (https://www.aswinvanwoudenberg.com | https://github.com/afvanwoudenberg)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "Wgg0MzK1N_-G" | |
}, | |
"source": [ | |
"## Setup" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"id": "UpsaRfQ7vQaW" | |
}, | |
"outputs": [], | |
"source": [ | |
"!apt install shellinabox &> /dev/null\n", | |
"!nohup shellinaboxd --disable-ssl --no-beep --port=8000 --css /etc/shellinabox/options-enabled/00_White\\ On\\ Black.css -s \"/:root:root:/root:/bin/bash -c bash -i\" &> /dev/null &\n", | |
"!yes | /usr/local/sbin/unminimize &> /dev/null" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "CHf_Xth5DlFz" | |
}, | |
"source": [ | |
"## Open a terminal in an iframe" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 421 | |
}, | |
"id": "a9QVOupNvQUE", | |
"outputId": "f47990ba-972d-4a4a-c199-1c25ff434b0a" | |
}, | |
"outputs": [], | |
"source": [ | |
"from google.colab.output import serve_kernel_port_as_iframe\n", | |
"serve_kernel_port_as_iframe(8000)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "rrFVgHJ_D1zG" | |
}, | |
"source": [ | |
"## Open a terminal in a browser tab" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
}, | |
"id": "SEvq-L0W0aWc", | |
"outputId": "fcfa0cf2-454e-4e3f-8293-debed2314f2d" | |
}, | |
"outputs": [], | |
"source": [ | |
"from google.colab.output import serve_kernel_port_as_window\n", | |
"serve_kernel_port_as_window(8000, anchor_text = \"Open a terminal\")" | |
] | |
} | |
], | |
"metadata": { | |
"colab": { | |
"authorship_tag": "ABX9TyNq2eI0EnsuVf2EJGSMtvbt", | |
"include_colab_link": true, | |
"mount_file_id": "1oZ942ZJf9A9-Mr6x5FodScb-0vrXt30M", | |
"provenance": [] | |
}, | |
"kernelspec": { | |
"display_name": "Python 3 (ipykernel)", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.11.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment