├── .gitignore ├── LICENSE ├── README.md ├── Screenshots ├── ss.png ├── ss2.png └── ss3.png ├── VSColab ├── __init__.py ├── __pycache__ │ └── code.cpython-39.pyc └── code.py ├── requirements.txt └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | env/ 2 | build/ 3 | VSColab.egg-info/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Anusikh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VSColab 2 | 3 | Use Google Colab GPU's and TPU's via an ssh connection locally in your device. 4 | 5 | [![license](https://img.shields.io/badge/license-MIT-blue.svg)](/LICENSE) 6 | ![python version](https://img.shields.io/badge/python-3.6%2C3.7%2C3.8-blue?logo=python) 7 | 8 | ### Installation: 9 | 10 | Installation is easy! 11 | 12 | ``` 13 | $ pip install VSColab 14 | ``` 15 | 16 | Using this package we can ssh into the Google Colab instance and also perform remote developement using VSCode. 17 | 18 | ### What's New in 0.1.4: 19 | 20 | - `GetSSH()` function automates the process of getting the Tunnel URL. 21 | 22 | ### Getting Started: 23 | 24 | - Install the package 25 | - Use the `Connect()` function to create an Ngrok tunnel, by passing a password string as a parameter. 26 | - Then Enter the Authentication Key (which can be obtained from:https://dashboard.ngrok.com/auth/your-authtoken) and press Enter. 27 | - To get the ssh command, run the `GetSSH()` function. 28 | - Use the `VSconfig()` function to get the contents for the VSCode Config file, by passing the Tunnel URL (which can be obtained from the `GetSSH()` function). 29 | - To kill the tunnel, use the `Kill()` function. 30 | 31 | ### Colab starter notebook: 32 | 33 | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1tZki6bp9x81jzn05zczR7aK03owsAscd?usp=sharing) 34 | 35 | ### Remote development with VSCode: 36 | 37 | - First create a tunnel using the `Connect()` function. 38 | - Use the `VSconfig()` function to get the contents for the VSCode Config file, by passing the Tunnel URL (which can be obtained from the `GetSSH()` function). 39 | - Then install the **remote-ssh** plugin in VSCode, and click the button at the bottom left corner. 40 | - Then select the **Open Configuration Files..** option and enter the copied text there. 41 | - Then select the **Connect to Host..** option and Enter the password when asked. 42 | - **Viola!! A fully functional Development environment powered by the GPU's and TPU's of Google Colab** 43 | 44 | ![](Screenshots/ss3.png) 45 | ![](Screenshots/ss.png) 46 | ![](Screenshots/ss2.png) 47 | 48 | ### Note: 49 | 50 | If the command `$ nvidia-smi` doesn't work in the ssh session, simply type : 51 | 52 | ``` 53 | export LD_PRELOAD=/usr/lib64-nvidia/libnvidia-ml.so 54 | ``` 55 | 56 | Then press Enter. 57 | -------------------------------------------------------------------------------- /Screenshots/ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anusikh/VSColab/449d137f9f33ae547a59c2154154e2fb75d13679/Screenshots/ss.png -------------------------------------------------------------------------------- /Screenshots/ss2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anusikh/VSColab/449d137f9f33ae547a59c2154154e2fb75d13679/Screenshots/ss2.png -------------------------------------------------------------------------------- /Screenshots/ss3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anusikh/VSColab/449d137f9f33ae547a59c2154154e2fb75d13679/Screenshots/ss3.png -------------------------------------------------------------------------------- /VSColab/__init__.py: -------------------------------------------------------------------------------- 1 | from .code import Connect, Kill, VSConfig, GetSSH 2 | -------------------------------------------------------------------------------- /VSColab/__pycache__/code.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anusikh/VSColab/449d137f9f33ae547a59c2154154e2fb75d13679/VSColab/__pycache__/code.cpython-39.pyc -------------------------------------------------------------------------------- /VSColab/code.py: -------------------------------------------------------------------------------- 1 | import getpass 2 | import os 3 | import subprocess 4 | import requests 5 | from re import sub 6 | 7 | def Connect(password): 8 | subprocess.call("apt-get install -qq -o=Dpkg::Use-Pty=0 openssh-server pwgen > /dev/null", shell=True) 9 | subprocess.call(f'echo root:{password} | chpasswd',shell=True) 10 | subprocess.call('mkdir -p /var/run/sshd', shell=True) 11 | subprocess.call('echo "PermitRootLogin yes" >> /etc/ssh/sshd_config', shell=True) 12 | subprocess.call('echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config', shell=True) 13 | print("username: root") 14 | print("password: ", password) 15 | get_ipython().system_raw('/usr/sbin/sshd -D &') 16 | subprocess.call('wget -q -c -nc https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip',shell=True) 17 | subprocess.call('unzip -qq -n ngrok-stable-linux-amd64.zip', shell=True) 18 | print("Get your authtoken from https://dashboard.ngrok.com/auth") 19 | authtoken = getpass.getpass() 20 | get_ipython().system_raw('./ngrok authtoken $authtoken && ./ngrok tcp 22 &') 21 | 22 | def VSConfig(str): 23 | print("Host VSConfig") 24 | print(f"\tHostName {str[6:20]}") 25 | print("\tUser root") 26 | print(f"\tPort {str[21:26]}") 27 | 28 | def GetSSH(): 29 | tun = requests.get('http://localhost:4040/api/tunnels') 30 | url = tun.json()['tunnels'][0]['public_url'] 31 | str_ssh = sub("tcp://", "", url) 32 | str_ssh = sub(":", " -p ", str_ssh) 33 | str_ssh = "ssh root@" + str_ssh 34 | print("Tunnel URL: ") 35 | print(url) 36 | print("SSH Command: ") 37 | print(str_ssh) 38 | 39 | 40 | def Kill(): 41 | os.system("kill $(ps aux | grep './ngrok' | awk '{print $2}')") 42 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | bleach==3.3.0 2 | certifi==2020.12.5 3 | chardet==4.0.0 4 | colorama==0.4.4 5 | docutils==0.17.1 6 | idna==2.10 7 | importlib-metadata==4.0.1 8 | keyring==23.0.1 9 | packaging==20.9 10 | pkginfo==1.7.0 11 | Pygments==2.9.0 12 | pyparsing==2.4.7 13 | pywin32-ctypes==0.2.0 14 | readme-renderer==29.0 15 | requests==2.25.1 16 | requests-toolbelt==0.9.1 17 | rfc3986==1.5.0 18 | six==1.16.0 19 | tqdm==4.60.0 20 | twine==3.4.1 21 | urllib3==1.26.4 22 | webencodings==0.5.1 23 | zipp==3.4.1 24 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | with open('README.md') as readme_file: 4 | long_description = readme_file.read() 5 | 6 | 7 | if __name__ == "__main__": 8 | setup( 9 | name='VSColab', 10 | version='0.1.4', 11 | description='SSH into Colab Notebooks and use VSCode for remote development', 12 | long_description=long_description, 13 | long_description_content_type="text/markdown", 14 | license='MIT License', 15 | packages=find_packages(), 16 | include_package_data=True, 17 | author='Anusikh Panda', 18 | author_email='anusikh2001@gmail.com', 19 | url = "https://github.com/anusikh/VSColab", 20 | platforms=["linux", "unix"], 21 | python_requires=">3.6.0", 22 | keywords=['VSColab', 'Colab', 'VS'] 23 | ) --------------------------------------------------------------------------------