├── README.md
└── Colab_RDP.ipynb
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Collab-Rdp
4 |
5 | ## RDP - or Remote Desktop Protocole helps you to connect to a Remote Desktop System and Control it just like any other normal Software.(similar to using using Ubuntu on Virtual Box)
6 | ## Google Collab provides you upto 12 hours of compute time. *There would be no restrtions on sites or applications*
7 | ## You can follow the steps given to connect to a collab system via Chrome Remote Desktop.
8 |
9 |
10 | ## To open the notebook Click on below button
11 |
12 |
13 |
14 | This notebook will be open
15 |
16 | 
17 |
18 | ## Step - 1 Connection
19 |
20 | **In Right Corner Click on connect arrow**
21 |
22 | 
23 |
24 | **After that you will see some options like**
25 |
26 | 
27 |
28 | **click on `connect to hosted runtime` which will allocate & connect to google cloud inctance**
29 | ---------
30 |
31 | > You can skip above step and dirctly click on run button of create user cell all the above procees will be done automatically
32 |
33 | ## Step - 1-a User Creation
34 |
35 | user and password are used for machine and will be needed if you lock the linux machine
36 |
37 | 
38 |
39 | After you click on run button you will get a warning dilog box click on run anyway
40 |
41 | 
42 |
43 | now you will see user creation process will be started and after few seconds you will see a user is created successfully
44 |
45 | 
46 |
47 | ## Step - 2 RDP conection using google remote desktop
48 |
49 | visit this link
50 |
51 | 
52 |
53 |
54 | you will see install button in url tab before bookmark button
55 | click it to install in your desktop so that you do not have to open browser
56 |
57 |
58 | 
59 |
60 |
61 |
62 | now you will see a icon in desktop
63 |
64 | 
65 |
66 | **open that**
67 |
68 | you will see window like this
69 |
70 | 
71 |
72 |
73 | ## Step 3 - Authorization
74 |
75 | click on begin button
76 |
77 | 
78 |
79 |
80 | then click on next
81 |
82 | 
83 |
84 |
85 | then click on authorise
86 |
87 | 
88 |
89 |
90 | now google sign in dilog will pop up then select any one of account to authorise
91 |
92 | 
93 |
94 |
95 | **choose any one of the account {next time you have to use same account}**
96 |
97 | after authentication some key will be genreted
98 |
99 | 
100 |
101 | you have to copy key of Debian Linux
102 |
103 | 
104 |
105 | ## Step - 4 Configuration
106 |
107 | Paste this key to crp text field in notebook
108 |
109 | 
110 |
111 | > **You Can change the `pin` if you want it will required in connecting with the inctance**
112 |
113 | After that click run button of RDP cell then it will install some tools
114 |
115 | 
116 |
117 |
118 | 
119 |
120 | after Installation completed then go to the google remote desktop
121 |
122 |
123 | 
124 |
125 |
126 | **And click on `remote access`**
127 |
128 | 
129 |
130 | after that you will see an online instance(remote device)
131 |
132 | 
133 |
134 | click on that you will see connecting
135 |
136 | 
137 |
138 | after connecting copy the pin from the notebook in `RDP Cell`
139 |
140 | 
141 |
142 | and paste in the text field in google remote desktop
143 |
144 | 
145 |
146 | then check the checkbox
147 |
148 | 
149 |
150 | and click on the arrow button
151 |
152 | 
153 |
154 | it will show connecting
155 |
156 | 
157 |
158 | after connectimg it will open the linux instance
159 |
160 | 
161 |
162 | click on `use default config`
163 |
164 | 
165 |
166 | click on browser from the task bar at bottom
167 |
168 | 
169 |
170 |
171 | then click on `ok`
172 |
173 | 
174 |
175 |
176 | now chrome will be open
177 |
178 | 
179 |
180 |
181 | now create new tab and check the speed
182 |
183 | 
184 |
185 |
186 | 
187 |
188 |
189 | ---------
190 |
191 | # some extra config
192 |
193 | ### 1 hiding tab bar
194 |
195 | for hiding tab bar right click on tab and then go to panel and then panel prefrence
196 |
197 | 
198 |
199 |
200 | then a dialog will be open
201 |
202 | 
203 |
204 | then select
205 |
206 | 
207 |
208 | to
209 |
210 | 
211 |
212 | 
213 |
214 |
215 | ### 2 to enable copy paste
216 |
217 | click on arrow at right side of the screen
218 |
219 | 
220 |
221 | then click on `begin`
222 |
223 | 
224 |
225 |
226 | then `allow`
227 |
228 | 
229 |
230 | then `ok`
231 |
232 | 
233 |
234 | Now you can copy & paste anything from remote desktop
235 |
--------------------------------------------------------------------------------
/Colab_RDP.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "name": "Colab RDP.ipynb",
7 | "provenance": [],
8 | "collapsed_sections": []
9 | },
10 | "kernelspec": {
11 | "display_name": "Python 3",
12 | "name": "python3"
13 | }
14 | },
15 | "cells": [
16 | {
17 | "cell_type": "markdown",
18 | "metadata": {
19 | "id": "iLh_9SkSut4u"
20 | },
21 | "source": [
22 | "# **Google Colab Remote Desktop** : \n",
23 | "Use any site or app without any restrictions.\n",
24 | "\n",
25 | "To read the step **[Collab Rdp](https://github.com/Meghdut-Mandal/Collab-Rdp)**"
26 | ]
27 | },
28 | {
29 | "cell_type": "code",
30 | "metadata": {
31 | "cellView": "form",
32 | "id": "t4yNp3KmLtZ6"
33 | },
34 | "source": [
35 | "#@title **Create User**\n",
36 | "#@markdown Enter Username and Password\n",
37 | "\n",
38 | "username = \"user\" #@param {type:\"string\"}\n",
39 | "password = \"root\" #@param {type:\"string\"}\n",
40 | "\n",
41 | "print(\"Creating User and Setting it up\")\n",
42 | "\n",
43 | "# Creation of user\n",
44 | "! sudo useradd -m $username &> /dev/null\n",
45 | "\n",
46 | "# Add user to sudo group\n",
47 | "! sudo adduser $username sudo &> /dev/null\n",
48 | " \n",
49 | "# Set password of user to 'root'\n",
50 | "! echo '$username:$password' | sudo chpasswd\n",
51 | "\n",
52 | "# Change default shell from sh to bash\n",
53 | "! sed -i 's/\\/bin\\/sh/\\/bin\\/bash/g' /etc/passwd\n",
54 | "\n",
55 | "print(\"User Created and Configured\")"
56 | ],
57 | "execution_count": null,
58 | "outputs": []
59 | },
60 | {
61 | "cell_type": "code",
62 | "metadata": {
63 | "id": "Q6bl1b0EifVG",
64 | "cellView": "form"
65 | },
66 | "source": [
67 | "#@title **RDP**\n",
68 | "#@markdown It takes 4-5 minutes for installation\n",
69 | "\n",
70 | "#@markdown Visit http://remotedesktop.google.com/headless and Copy the command after authentication\n",
71 | "\n",
72 | "CRP = \"DISPLAY= /opt/google/chrome-remote-desktop/start-host --code=\\\"4/0AY0e-g7xa6YDmYpGz9XFNiHVoqU10E150l-N-0MJT5hgBIR6-JA_OheBT7sBHD3fQH9rHw\\\" --redirect-url=\\\"https://remotedesktop.google.com/_/oauthredirect\\\" --name=$(hostname)\" #@param {type:\"string\"}\n",
73 | "\n",
74 | "#@markdown Enter a pin more or equal to 6 digits\n",
75 | "Pin = 123394 #@param {type: \"integer\"}\n",
76 | "\n",
77 | "def CRD():\n",
78 | " with open('install.sh', 'w') as script:\n",
79 | " script.write(\"\"\"#! /bin/bash\n",
80 | "\n",
81 | "b='\\033[1m'\n",
82 | "r='\\E[31m'\n",
83 | "g='\\E[32m'\n",
84 | "c='\\E[36m'\n",
85 | "endc='\\E[0m'\n",
86 | "enda='\\033[0m'\n",
87 | "\n",
88 | "printf \"\\n\\n$c$b Loading Installer $endc$enda\" >&2\n",
89 | "if sudo apt-get update &> /dev/null\n",
90 | "then\n",
91 | " printf \"\\r$g$b Installer Loaded $endc$enda\\n\" >&2\n",
92 | "else\n",
93 | " printf \"\\r$r$b Error Occured $endc$enda\\n\" >&2\n",
94 | " exit\n",
95 | "fi\n",
96 | "\n",
97 | "printf \"\\n$g$b Installing Chrome Remote Desktop $endc$enda\" >&2\n",
98 | "{\n",
99 | " wget https://dl.google.com/linux/direct/chrome-remote-desktop_current_amd64.deb\n",
100 | " sudo dpkg --install chrome-remote-desktop_current_amd64.deb\n",
101 | " sudo apt install --assume-yes --fix-broken\n",
102 | "} &> /dev/null &&\n",
103 | "printf \"\\r$c$b Chrome Remote Desktop Installed $endc$enda\\n\" >&2 ||\n",
104 | "{ printf \"\\r$r$b Error Occured $endc$enda\\n\" >&2; exit; }\n",
105 | "sleep 3\n",
106 | "\n",
107 | "printf \"$g$b Installing Desktop Environment $endc$enda\" >&2\n",
108 | "{\n",
109 | " sudo DEBIAN_FRONTEND=noninteractive \\\n",
110 | " apt install --assume-yes xfce4 desktop-base xfce4-terminal\n",
111 | " sudo bash -c 'echo \"exec /etc/X11/Xsession /usr/bin/xfce4-session\" > /etc/chrome-remote-desktop-session' \n",
112 | " sudo apt remove --assume-yes gnome-terminal\n",
113 | " sudo apt install --assume-yes xscreensaver\n",
114 | " sudo systemctl disable lightdm.service\n",
115 | "} &> /dev/null &&\n",
116 | "printf \"\\r$c$b Desktop Environment Installed $endc$enda\\n\" >&2 ||\n",
117 | "{ printf \"\\r$r$b Error Occured $endc$enda\\n\" >&2; exit; }\n",
118 | "sleep 3\n",
119 | "\n",
120 | "printf \"$g$b Installing Google Chrome $endc$enda\" >&2\n",
121 | "{\n",
122 | " wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb\n",
123 | " sudo dpkg --install google-chrome-stable_current_amd64.deb\n",
124 | " sudo apt install --assume-yes --fix-broken\n",
125 | "} &> /dev/null &&\n",
126 | "printf \"\\r$c$b Google Chrome Installed $endc$enda\\n\" >&2 ||\n",
127 | "printf \"\\r$r$b Error Occured $endc$enda\\n\" >&2\n",
128 | "sleep 3\n",
129 | "\n",
130 | "printf \"$g$b Installing other Tools $endc$enda\" >&2\n",
131 | "if sudo apt install nautilus nano -y &> /dev/null\n",
132 | "then\n",
133 | " printf \"\\r$c$b Other Tools Installed $endc$enda\\n\" >&2\n",
134 | "else\n",
135 | " printf \"\\r$r$b Error Occured $endc$enda\\n\" >&2\n",
136 | "fi\n",
137 | "sleep 3\n",
138 | "\n",
139 | "printf \"\\n$g$b Installation Completed $endc$enda\\n\\n\" >&2\"\"\")\n",
140 | "\n",
141 | " ! chmod +x install.sh\n",
142 | " ! ./install.sh\n",
143 | "\n",
144 | " # Adding user to CRP group\n",
145 | " ! sudo adduser $username chrome-remote-desktop &> /dev/null\n",
146 | "\n",
147 | " # Finishing Work\n",
148 | " ! su - $username -c \"\"\"$CRP --pin=$Pin\"\"\" &> /dev/null\n",
149 | "\n",
150 | " print(\"Finished Succesfully\")\n",
151 | "\n",
152 | "try:\n",
153 | " if username:\n",
154 | " if CRP == \"\":\n",
155 | " print(\"Please enter authcode from the given link\")\n",
156 | " elif len(str(Pin)) < 6:\n",
157 | " print(\"Enter a pin more or equal to 6 digits\")\n",
158 | " else:\n",
159 | " CRD()\n",
160 | "except NameError:\n",
161 | " print(\"username variable not found\")\n",
162 | " print(\"Create a User First\")"
163 | ],
164 | "execution_count": null,
165 | "outputs": []
166 | },
167 | {
168 | "cell_type": "code",
169 | "metadata": {
170 | "cellView": "form",
171 | "id": "vk2qtOTGIFsQ"
172 | },
173 | "source": [
174 | "#@title **Google Drive Mount**\n",
175 | "#@markdown Google Drive used as Persistance HDD for files.
\n",
176 | "#@markdown Mounted at `user` Home directory inside drive folder\n",
177 | "#@markdown (If `username` variable not defined then use root as default).\n",
178 | "\n",
179 | "def MountGDrive():\n",
180 | " from google.colab import drive\n",
181 | "\n",
182 | " ! runuser -l $user -c \"yes | python3 -m pip install --user google-colab\" > /dev/null 2>&1\n",
183 | "\n",
184 | " mount = \"\"\"from os import environ as env\n",
185 | "from google.colab import drive\n",
186 | "\n",
187 | "env['CLOUDSDK_CONFIG'] = '/content/.config'\n",
188 | "drive.mount('{}')\"\"\".format(mountpoint)\n",
189 | "\n",
190 | " with open('/content/mount.py', 'w') as script:\n",
191 | " script.write(mount)\n",
192 | "\n",
193 | " ! runuser -l $user -c \"python3 /content/mount.py\"\n",
194 | "\n",
195 | "try:\n",
196 | " if username:\n",
197 | " mountpoint = \"/home/\"+username+\"/drive\"\n",
198 | " user = username\n",
199 | "except NameError:\n",
200 | " print(\"username variable not found, mounting at `/content/drive' using `root'\")\n",
201 | " mountpoint = '/content/drive'\n",
202 | " user = 'root'\n",
203 | "\n",
204 | "MountGDrive()"
205 | ],
206 | "execution_count": null,
207 | "outputs": []
208 | },
209 | {
210 | "cell_type": "code",
211 | "metadata": {
212 | "cellView": "form",
213 | "id": "8icuQYnyKDLk"
214 | },
215 | "source": [
216 | "#@title **SSH**\n",
217 | "\n",
218 | "! pip install colab_ssh --upgrade &> /dev/null\n",
219 | "\n",
220 | "Ngrok = False #@param {type:'boolean'}\n",
221 | "Agro = False #@param {type:'boolean'}\n",
222 | "\n",
223 | "\n",
224 | "#@markdown Copy authtoken from https://dashboard.ngrok.com/auth (only for ngrok)\n",
225 | "ngrokToken = \"\" #@param {type:'string'}\n",
226 | "\n",
227 | "\n",
228 | "def runNGROK():\n",
229 | " from colab_ssh import launch_ssh\n",
230 | " from IPython.display import clear_output\n",
231 | " launch_ssh(ngrokToken, password)\n",
232 | " clear_output()\n",
233 | "\n",
234 | " print(\"ssh\", username, end='@')\n",
235 | " ! curl -s http://localhost:4040/api/tunnels | python3 -c \\\n",
236 | " \"import sys, json; print(json.load(sys.stdin)['tunnels'][0]['public_url'][6:].replace(':', ' -p '))\"\n",
237 | "\n",
238 | "\n",
239 | "def runAgro():\n",
240 | " from colab_ssh import launch_ssh_cloudflared\n",
241 | " launch_ssh_cloudflared(password=password)\n",
242 | "\n",
243 | "\n",
244 | "try:\n",
245 | " if username:\n",
246 | " pass\n",
247 | " elif password:\n",
248 | " pass\n",
249 | "except NameError:\n",
250 | " print(\"No user found using username and password as 'root'\")\n",
251 | " username='root'\n",
252 | " password='root'\n",
253 | "\n",
254 | "\n",
255 | "if Agro and Ngrok:\n",
256 | " print(\"You can't do that\")\n",
257 | " print(\"Select only one of them\")\n",
258 | "elif Agro:\n",
259 | " runAgro()\n",
260 | "elif Ngrok:\n",
261 | " if ngrokToken == \"\":\n",
262 | " print(\"No ngrokToken Found, Please enter it\")\n",
263 | " else:\n",
264 | " runNGROK()\n",
265 | "else:\n",
266 | " print(\"Select one of them\")"
267 | ],
268 | "execution_count": null,
269 | "outputs": []
270 | },
271 | {
272 | "cell_type": "code",
273 | "metadata": {
274 | "cellView": "form",
275 | "id": "OXsG6_pxeEFu"
276 | },
277 | "source": [
278 | "#@title Package Installer { vertical-output: true }\n",
279 | "run = False #@param {type:\"boolean\"}\n",
280 | "#@markdown *Package management actions (gasp)*\n",
281 | "action = \"Install\" #@param [\"Install\", \"Check Installed\", \"Remove\"] {allow-input: true}\n",
282 | "\n",
283 | "package = \"wget\" #@param {type:\"string\"}\n",
284 | "system = \"apt\" #@param [\"apt\", \"\"]\n",
285 | "\n",
286 | "def install(package=package, system=system):\n",
287 | " if system == \"apt\":\n",
288 | " !apt --fix-broken install > /dev/null 2>&1\n",
289 | " !killall apt > /dev/null 2>&1\n",
290 | " !rm /var/lib/dpkg/lock-frontend\n",
291 | " !dpkg --configure -a > /dev/null 2>&1\n",
292 | "\n",
293 | " !apt-get install -o Dpkg::Options::=\"--force-confold\" --no-install-recommends -y $package\n",
294 | " \n",
295 | " !dpkg --configure -a > /dev/null 2>&1 \n",
296 | " !apt update > /dev/null 2>&1\n",
297 | "\n",
298 | " !apt install $package > /dev/null 2>&1\n",
299 | "\n",
300 | "def check_installed(package=package, system=system):\n",
301 | " if system == \"apt\":\n",
302 | " !apt list --installed | grep $package\n",
303 | "\n",
304 | "def remove(package=package, system=system):\n",
305 | " if system == \"apt\":\n",
306 | " !apt remove $package\n",
307 | "\n",
308 | "if run:\n",
309 | " if action == \"Install\":\n",
310 | " install()\n",
311 | " if action == \"Check Installed\":\n",
312 | " check_installed()\n",
313 | " if action == \"Remove\":\n",
314 | " remove()"
315 | ],
316 | "execution_count": null,
317 | "outputs": []
318 | },
319 | {
320 | "cell_type": "code",
321 | "metadata": {
322 | "cellView": "form",
323 | "id": "UoeBdz6_KE6a"
324 | },
325 | "source": [
326 | "#@title **Colab Shutdown**\n",
327 | "\n",
328 | "#@markdown To Kill NGROK Tunnel\n",
329 | "NGROK = False #@param {type:'boolean'}\n",
330 | "\n",
331 | "#@markdown To Unmount GDrive\n",
332 | "GDrive = True #@param {type:'boolean'}\n",
333 | "\n",
334 | "#@markdown To Sleep Colab\n",
335 | "Sleep = True #@param {type:'boolean'}\n",
336 | "\n",
337 | "if NGROK:\n",
338 | " ! killall ngrok\n",
339 | "\n",
340 | "if GDrive:\n",
341 | " with open('/content/unmount.py', 'w') as unmount:\n",
342 | " unmount.write(\"\"\"from google.colab import drive\n",
343 | "drive.flush_and_unmount()\"\"\")\n",
344 | " \n",
345 | " try:\n",
346 | " if user:\n",
347 | " ! runuser $user -c 'python3 /content/unmount.py'\n",
348 | " except NameError:\n",
349 | " print(\"Google Drive not Mounted\")\n",
350 | "\n",
351 | "if Sleep:\n",
352 | " ! sleep 43200"
353 | ],
354 | "execution_count": null,
355 | "outputs": []
356 | }
357 | ]
358 | }
--------------------------------------------------------------------------------