├── Dockerfile ├── README.md ├── get_ssh_command.py ├── images ├── check_ram.png ├── clone_code.png ├── connect_auto.png ├── docker_ps.png ├── instance.png ├── lscpu.png ├── ngrok_service.png ├── nvidia_smi.png ├── run_all.png ├── scp.png ├── ssh.png ├── ssh_ngrok_service.png ├── tensorboard.png ├── training.png └── vminstance.png ├── ngrok-config ├── rsynfile.sh ├── run.sh ├── run_client.sh ├── run_docker.sh ├── server_for_download.py ├── setup_ngrok_server.sh └── sshd_config /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:16.04 2 | RUN apt-get update 3 | RUN apt-get install -y gcc musl-dev git mercurial bash openssl make python3 wget 4 | RUN wget -P /tmp https://dl.google.com/go/go1.11.5.linux-amd64.tar.gz 5 | RUN tar -C /usr/local -xzf /tmp/go1.11.5.linux-amd64.tar.gz 6 | RUN rm /tmp/go1.11.5.linux-amd64.tar.gz 7 | ENV GOPATH /go 8 | ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH 9 | RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" 10 | WORKDIR /app 11 | COPY setup_ngrok_server.sh /app/setup_ngrok_server.sh 12 | RUN sh setup_ngrok_server.sh 13 | WORKDIR /app/run 14 | COPY server_for_download.py /app/run/server_for_download.py 15 | COPY run.sh /app/run/run.sh 16 | CMD ["sh", "run.sh"] 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Setup ngrok server và sử dụng colab như một remote server 2 | 3 | ## Table of Contents 4 | * [About the Project](#1-about-the-project) 5 | * [Getting Started](#2-getting-started) 6 | * [Prerequisites](#21-prerequisites) 7 | * [The first option:Use service of ngrok](#3-the-first-option-use-service-of-ngrok) 8 | * [The second option: Build own ngrok server](#4-the-second-option-build-own-ngrok-server) 9 | * [Setup server](41-setup-server) 10 | * [Setup on Colab notebook](42-setup-on-colab-notebook) 11 | * [Results](#5-results) 12 | * [Check hardware Colab](#51-check-hardware-colab) 13 | * [Training sample](#52-training-sample) 14 | * [Tips & Tricks]() 15 | * [Code, auto upload, run, and debug source code with Pycharm Professional]() 16 | * [Documents]() 17 | 18 | ## 1. About the Project 19 | 20 | Trong qúa trình làm việc sử dụng Google colab, mình gặp một vấn đề rất khó chịu là Colab sử dụng Jupyter Notebook để làm 21 | việc. Một số vấn đề có thể kể đến là: 22 | 23 | - **Code xấu:** Code cả project trong chỉ một notebook của colab thì nó xấu vch, chưa kể là cái gợi ý function của nó cũng 24 | chậm làm giảm năng suất code, không phê được như Pycharm. Có thể khắc phục bằng cách là code ở local 25 | và push lên github sau đó clone về colab. Cách này code đẹp tí nhưng bắt tay vào làm thì hơi cực chứ không dễ. 26 | 27 | - **Khó debug:** Bạn nào đã từng sử dụng Pycharm ở các máy local thì sẽ thấy n kỳ diệu thế nào. 28 | 29 | - **Sử dụng terminal không linh hoạt:** Sử dụng terminal trong colab sida sau cái code xấu vừa chậm vừa khó nhìn. 30 | Mỗi lần muốn chạy một câu lệnh mới là xóa cell hiện tại đi hoặc phải tạo một cell mới 31 | 32 | - **Phải lưu kết quả vào google drive:** Tốn dung lượng drive. Phức tạp khi code và sử dụng. 33 | - **Khó theo dõi được Tensorboard** 34 | - ...... 35 | 36 | Trong project này mình sẽ chia sẻ một cách làm việc hiệu quả với Google colab cho các bạn mới sử dụng colab. Một số chức năng được 37 | cung cấp: 38 | - ssh vào colab và thao tác trên terminal với độ trễ thấp. 39 | - Tự động download các kết quả(checkpoint, log,...) về local thay vì phải lưu vào 40 | drive. 41 | - Theo dõi Tensorboard từ local browser, hoặc bất kỳ thiết bị nào truy cập được internet. 42 | - Code và debug với Pycharm ở local và tự động đồng bộ code lên colab server. 43 | 44 | ## 2. Getting started 45 | ### 2.1 Prerequisites 46 | 47 | Để thực hiện project này thì sẽ cần: 48 | - Một server với IP tĩnh. Để demo mình sẽ sử dụng một máy ảo trên google cloud(Các bạn ra 49 | ngân hàng đăng ký một thẻ debit, dùng thẻ này để đăng ký sẽ được $300 free trong vòng một năm). 50 | - Sử dụng linux terminal cơ bản. 51 | - Máy tính để code. Laptop mình sử dụng có tuổi đời 7 năm, ram 4Gb. 52 | 53 | ## 3. The first option: Use service of ngrok 54 | 55 | Cách này dễ làm nhưng độ trễ khi sử dụng các câu lệnh trên terminal lớn và bạn chỉ có thể mở ra một cổng để truy cập. 56 | Nên mình ít khi sử dụng cách này. 57 | 58 | Bước 1: Truy cập vào trang https://ngrok.com , tạo acccount. Sau đó bạn sẽ có được một đoạn mã authtoken. 59 | 60 | Bước 2: Tạo ra một file Colab notebook có nội dung giống của mình như [link](https://colab.research.google.com/drive/1s9aQsgg3IiWZom67Gdoue6flXeODpHz9?usp=sharing) 61 | 62 | Bước 3: Config các tham số ở cell thứ 2 63 | ``` 64 | import os 65 | os.environ['authtoken'] = "1aDEELv5Yb24tBm509rGVDX7sDk_2oHnRo1bfpgiKSrRjnkcB" 66 | os.environ['SSH_KEY'] = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDIykhpbjm/Yj3wZ55aMVyOy9DzKHdXh8ihs2SeQFzGKKsDcmCDyYb72g9nlA6gZVKFf00tD6TcMofoMu2O19IyhzM9/Ttnk32UXyVcwG83UJrU/lSh4PdFyminyNIJUQ4LAtpjOoObaLYYrYk1cPrq3qHV9prhKgZlmbsiMa/hDY4LFG6vgn6SdAWqlPRH8yvIVp6YdAH6LPR5z5JIL8pbQn71LeuJbJMsR50TYM3HvaTDZMim1Bcw0INGxp/hNJ523CHOI0iCLwqSFKd7HgxOq/tnf2rCyqcCKJH3yHkOATvgxoqAaFVhPp2WjWKX+BlV9Oq8Xzb3HzirEsE/HbT/ tanlm@pc11-All-Series-Invalid-entry-length-16-Fixed-up-to-11" 67 | ``` 68 | - authtoken: Token mà trang https://ngrok.com đưa cho bạn. 69 | - SSH_KEY: ssh public key của máy local. 70 | 71 | Bước 4: Run toàn bộ file colab notebook. Ở cell cuối cùng ta sẽ thấy một câu lệnh ssh hiện ra 72 | 73 | ![](images/ngrok_service.png) 74 | 75 | Copy câu lệnh này vào terminal thì ta có thể truy cập vào colab instance bằng SSH. 76 | 77 | ![](images/ssh_ngrok_service.png) 78 | 79 | 80 | ## 4. The second option: Build own ngrok server 81 | 82 | Cách này sẽ hơi khó hơn chút là tự cài đặt ngrok server của riêng mình. 83 | 84 | Bù lại ta sẽ có thể sử dụng terminal một cách gần như real-time và mở nhiều cổng hơn để sử dụng. 85 | 86 | Quá trình sẽ được chia thành 2 giai đoạn là setup server và setup client 87 | 88 | ### 4.1 Setup server 89 | #### 4.1.1 Create an instance on google cloud 90 | Mình tạo ra một máy ảo *g1-small 1vCPU, 1.7 GB memory* ở khu vực Hongkong với giá khoảng ~598 VNĐ/H. Quá rẻ cho một cuộc tình. 91 | 92 | Hệ điều hành mình sử dụng ở đây là Ubuntu-16.04 93 | 94 | ![](images/vminstance.png) 95 | 96 | Tiếp đến là cấu hình mở port và cài đặt docker. 97 | * Cấu hình server để mở các port: 7000, 8000, 8001, 4443, 10000-10050 để sử dụng. Gồm 2 bước: 98 | * Mở port với google cloud. Các bạn google. [Đây](https://www.youtube.com/watch?v=JmjqPpQdtW8) là một ví dụ với mở cổng 8080 trên google cloud 99 | * Mở port trên Ubuntu 100 | ``` 101 | sudo ufw allow 7000 102 | sudo ufw allow 8000 103 | sudo ufw allow 8001 104 | sudo ufw allow 4443 105 | sudo ufw allow 10000:10050 106 | ``` 107 | * Cài đặt docker. Đây là [hướng dẫn cài đặt](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04) trên Ubuntu-16.04 108 | 109 | #### 4.1.2 Build and run ngrok server: 110 | 111 | Đầu tiên là clone code và các file cài đặt về: 112 | ``` 113 | git clone https://github.com/tanle2694/ssh_colab 114 | ``` 115 | 116 | Build docker và run ngrok server: 117 | ``` 118 | cd ssh_colab 119 | chmod +x run_docker.sh 120 | ./run_docker.sh 121 | ``` 122 | 123 | Kiểm tra lại kết quả bằng câu lệnh 124 | ``` 125 | docker ps 126 | ``` 127 | Nếu thành công thì kết quả sẽ hiện ra là có một docker đang chạy như hình bên 128 | dưới 129 | 130 | ![](images/docker_ps.png) 131 | 132 | ### 4.2 Setup on Colab notebook: 133 | 134 | **Bước 1:** Tạo một file Colab notebook giống như trong file colab của mình trong [link](https://colab.research.google.com/drive/1Fmm5Ry_mjw69pUi_2y3wWJqzmaOROdvw?usp=sharing) 135 | 136 | **Bước 2:** Cấu hình các tham số trong Colab notebook 137 | 138 | **Cell 1:** 139 | ``` 140 | %%writefile /tmp/ngrok-config 141 | server_addr: colab.tunnel:4443 142 | trust_host_root_certs: false 143 | tunnels: 144 | ssh-app: 145 | remote_port: 10004 146 | proto: 147 | tcp: 22 148 | tensorboard-app: 149 | remote_port: 10006 150 | proto: 151 | tcp: 6006 152 | ``` 153 | Các bạn setup các thông số từ dòng tunnels trở xuống. Nếu không muốn thêm các cổng khác thì bạn giữ nguyên cell này. 154 | 155 | Ở đây là mình setup 2 tunnel: 156 | - *ssh-app:* dùng để map cổng 10004 trên ngrok server và cổng 22 trên máy Colab 157 | - *tensorboard-app:* map cổng 10006 trên ngrok server và cổng 6006 trên máy Colab 158 | 159 | Nếu các bạn muốn map các cổng khác thì có thể thêm vào bên dưới với format: 160 | ``` 161 | app-name: 162 | remote_port: xxx 163 | proto: 164 | tcp: yyy 165 | ``` 166 | 167 | **Cell 2:** 168 | ``` 169 | function ClickConnect(){ 170 | console.log("Working"); 171 | document 172 | .querySelector("#top-toolbar > colab-connect-button") 173 | .shadowRoot 174 | .querySelector("#connect") 175 | .click() 176 | } 177 | 178 | setInterval(ClickConnect,60000) 179 | ``` 180 | Trong quá trình run Colab notebook, nếu không có thao tác gì với notebook thì session có thể bị mất kết nối. 181 | 182 | Để giải quyết vấn đề này, đầu tiên hãy ấn phím F12, và copy nội dung trên vào console của trình duyệt như sau: 183 | 184 | ![](images/connect_auto.png) 185 | 186 | Sau 60s đoạn mã này sẽ tự động ấn nút *Connect* để tránh bị ngắt kết nối của session 187 | 188 | **Cell 3:** 189 | ``` 190 | import os 191 | os.environ['IP_SERVER'] = "35.186.148.224" 192 | os.environ['SSH_KEY'] = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDGB10CfGiSci1JqI1LkwRUv13kGBlhf0zD2GRkKz6ixpzb3F9AN40tB7s+oqwqCoD6puB6B8e/RUnRbqTefNyMN3rhMzCzLK+nWZHqZF9D0HV/1ngxvu+R1SZjFdasJ52kRm1l8z6OAy+CHglYgG3a/qkzEOkfoMt3CKkNwCy6O6FxYi2Kzr12OfcPsySUByBlZv1G7TIEA4sl0IIYoPhgu5IM2gLXEQcvJZO6TGMgTV+yzh1/oZamQo/JB4SRYQERhe8bFCjqbEwACT3+H1pfTU0sWQbhcB/mLhZU9Ide7XV9Xr+3vp8VOyvVuV+5WjOcquaPLM6ieVaT90zBPweT tanlm@tanlm" 193 | os.environ['APP_RUN'] = "ssh-app tensorboard-app" 194 | os.environ['TAG'] = "v1.0" 195 | ``` 196 | - IP_SERVER: public IP của ngrok server chúng ta đã sử dụng 197 | - SSH_KEY: ssh public-key của máy local 198 | - APP_RUN: ở đây mình chạy 2 app đã đăng ký là *ssh-app* và *tensorboard-app* 199 | - TAG: tag của code trên github. Phần này các bạn không cần sửa đổi 200 | 201 | **Bước 3:** Run tất cả các cell 202 | 203 | ![](images/run_all.png) 204 | 205 | Khi run xong thì tại cell cuối cùng ta sẽ thấy câu lệnh ssh hiện ra. 206 | 207 | ![](images/ssh.png) 208 | 209 | Copy câu lệnh trên vào terminal chúng ta sẽ truy cập vào được instance của Colab. 210 | 211 | ## 5. Results 212 | 213 | ### 5.1 Check hardware Colab: 214 | Mình đang sử dụng Colab Pro. Ta hãy thử xem Colab Pro có gì: 215 | 216 | - Check GPU với lệnh *nvidia-smi*, ta có GPU Tesla P100 16Gb VRAM 217 | ![](images/nvidia_smi.png) 218 | 219 | - Check CPU với lệnh *lscpu*, ta có 2 core CPU với xung nhịp 2.30GHz 220 | ![](images/lscpu.png) 221 | - Check RAM với lệnh *free -m*, ta có tổng cộng 13Gb Ram và còn có thể sử dụng 12Gb nữa 222 | ![](images/check_ram.png) 223 | 224 | 225 | ### 5.2 Training sample: 226 | Trước khi training cần phải setup code và data. 227 | **Bước 1:** Clone code từ github xuống. Hoặc thay vì clone thì các bạn có thể upload trực tiếp từ local lên cũng được 228 | 229 | `git clone https://github.com/tanle2694/mri_brain_segmentation` 230 | 231 | ![](images/clone_code.png) 232 | 233 | **Bước 2:** Upload data từ local lên. Sử dụng lệnh scp trỏ đến cổng 10004, để upload file *data_mri.zip* lên thư mục 234 | */root/data* trên Colab 235 | 236 | `scp -P 10004 data_mri.zip root@35.186.148.224:/root/data` 237 | 238 | ![](images/scp.png) 239 | 240 | **Bước 3:** Training và theo dõi kết quả. 241 | 242 | Mình thường sử dụng [tmux](https://kipalog.com/posts/Nghich-tmux) để làm việc với các remote server. 243 | Trong hình bên dưới là mình đang training ở panel bên trái và run Tensorboard ở pannel bên phải. 244 | 245 | ![](images/training.png) 246 | 247 | Ở local browser ta có thể theo dõi Tensorboard tại địa chỉ `http://35.186.148.224:10006` 248 | 249 | Link này bao gồm địa chỉ của server cài đặt ngrok-server (35.186.148.224) và port 10006 là port đã setup cho 250 | Tensorboard-app 251 | 252 | ![](images/tensorboard.png) 253 | 254 | 255 | **Bước 4:** Đồng bộ các checkpoint và log về local 256 | 257 | Mình đã setup sẵn một file [bash-script](https://github.com/tanle2694/ssh_colab/blob/master/rsynfile.sh) cho phép đồng 258 | bộ một thư mục trên Colab server xuống local: 259 | 260 | Các bạn chỉ cần setup các thông số: 261 | ``` 262 | REMOTE_IP="35.186.148.224" 263 | REMOTE_PORT="10004" 264 | REMOTE_DIR="/root/data/save_dir" 265 | LOCAL_DIR="/home/tanlm/Downloads/lgg-mri-segmentation/remote_save_dir" 266 | TIME_SLEEP=10 267 | ``` 268 | - REMOTE_IP: IP của ngrok-server 269 | - REMOTE_PORT: port dùng để ssh 270 | - REMOTE_DIR: Thư mục cần đồng bộ trên Colab server 271 | - LOCAL_DIR: Thư mục sẽ được đồng bộ xuống ở local 272 | - TIME_SLEEP: Thời gian dừng giữa các lần đồng bộ file tính theo second 273 | 274 | Sau khi setup các tham số xong thì chỉ cần chạy. Các checkpoint sẽ được đồng bộ xuống local mỗi 10 second: 275 | 276 | ``` 277 | chmod +x rsynfile.sh 278 | ./rsynfile.sh 279 | ``` 280 | 281 | ## 5. Tips & Tricks: 282 | 283 | ### 5.1 Code, auto upload run, auto upload 284 | **UPDATING** 285 | 286 | # 6. Documents: -------------------------------------------------------------------------------- /get_ssh_command.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import re 3 | import json 4 | import os 5 | url = "http://127.0.0.1:4040/http/in" 6 | 7 | r = requests.get(url) 8 | for line in r.text.split("\n"): 9 | if not line.__contains__("window.data"): 10 | continue 11 | r_match = re.match(r"^.*JSON\.parse\((.*)\);$", line) 12 | tunnel = json.loads(json.loads(r_match.group(1)))['UiState']['Tunnels'][0] 13 | port = tunnel['PublicUrl'][7:] 14 | print("ssh root@{} -p {}".format(os.environ['IP_SERVER'], port)) -------------------------------------------------------------------------------- /images/check_ram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanle2694/ssh_colab/a8c8b0b75f447716c6c36228c0d71d0458bc4220/images/check_ram.png -------------------------------------------------------------------------------- /images/clone_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanle2694/ssh_colab/a8c8b0b75f447716c6c36228c0d71d0458bc4220/images/clone_code.png -------------------------------------------------------------------------------- /images/connect_auto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanle2694/ssh_colab/a8c8b0b75f447716c6c36228c0d71d0458bc4220/images/connect_auto.png -------------------------------------------------------------------------------- /images/docker_ps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanle2694/ssh_colab/a8c8b0b75f447716c6c36228c0d71d0458bc4220/images/docker_ps.png -------------------------------------------------------------------------------- /images/instance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanle2694/ssh_colab/a8c8b0b75f447716c6c36228c0d71d0458bc4220/images/instance.png -------------------------------------------------------------------------------- /images/lscpu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanle2694/ssh_colab/a8c8b0b75f447716c6c36228c0d71d0458bc4220/images/lscpu.png -------------------------------------------------------------------------------- /images/ngrok_service.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanle2694/ssh_colab/a8c8b0b75f447716c6c36228c0d71d0458bc4220/images/ngrok_service.png -------------------------------------------------------------------------------- /images/nvidia_smi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanle2694/ssh_colab/a8c8b0b75f447716c6c36228c0d71d0458bc4220/images/nvidia_smi.png -------------------------------------------------------------------------------- /images/run_all.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanle2694/ssh_colab/a8c8b0b75f447716c6c36228c0d71d0458bc4220/images/run_all.png -------------------------------------------------------------------------------- /images/scp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanle2694/ssh_colab/a8c8b0b75f447716c6c36228c0d71d0458bc4220/images/scp.png -------------------------------------------------------------------------------- /images/ssh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanle2694/ssh_colab/a8c8b0b75f447716c6c36228c0d71d0458bc4220/images/ssh.png -------------------------------------------------------------------------------- /images/ssh_ngrok_service.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanle2694/ssh_colab/a8c8b0b75f447716c6c36228c0d71d0458bc4220/images/ssh_ngrok_service.png -------------------------------------------------------------------------------- /images/tensorboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanle2694/ssh_colab/a8c8b0b75f447716c6c36228c0d71d0458bc4220/images/tensorboard.png -------------------------------------------------------------------------------- /images/training.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanle2694/ssh_colab/a8c8b0b75f447716c6c36228c0d71d0458bc4220/images/training.png -------------------------------------------------------------------------------- /images/vminstance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanle2694/ssh_colab/a8c8b0b75f447716c6c36228c0d71d0458bc4220/images/vminstance.png -------------------------------------------------------------------------------- /ngrok-config: -------------------------------------------------------------------------------- 1 | server_addr: colab.tunnel:4443 2 | trust_host_root_certs: false 3 | tunnels: 4 | ssh-app: 5 | remote_port: 10022 6 | proto: 7 | tcp: 22 8 | tensorboard-app: 9 | remote_port: 10006 10 | proto: 11 | tcp: 6006 12 | -------------------------------------------------------------------------------- /rsynfile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | REMOTE_IP="35.186.148.224" 5 | REMOTE_PORT="10004" 6 | REMOTE_DIR="/root/data/save_dir" 7 | LOCAL_DIR="/home/tanlm/Downloads/lgg-mri-segmentation/remote_save_dir" 8 | TIME_SLEEP=10 9 | 10 | while [ true ] 11 | do 12 | echo "Rsyn from remote server" 13 | echo "rsync -avzhe ssh -p ${REMOTE_PORT} root@${REMOTE_IP}:${REMOTE_DIR} ${LOCAL_DIR}" 14 | sh -c "rsync -avzhe \"ssh -p ${REMOTE_PORT}\" root@${REMOTE_IP}:${REMOTE_DIR} ${LOCAL_DIR}" 15 | echo "Sleeping" 16 | sleep $TIME_SLEEP 17 | done -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | python3 server_for_download.py --file ngrok --port 7000 & 2 | ./ngrokd -tlsKey=device.key -tlsCrt=device.crt -domain="$NGROK_DOMAIN" -httpAddr=":8000" -httpsAddr=":8001" -------------------------------------------------------------------------------- /run_client.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | IP_SERVER="$1" 3 | SSH_KEY="$2" 4 | APP_RUN="$3" 5 | echo "IP_SERVER: $IP_SERVER, APP_RUN: $APP_RUN" 6 | mkdir -p ~/.ssh 7 | sudo apt-get install ssh 8 | mv sshd_config /etc/ssh/sshd_config 9 | echo $SSH_KEY >> ~/.ssh/authorized_keys 10 | service ssh restart 11 | 12 | echo "PermitRootLogin yes" >> /etc/ssh/sshd_config && echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config 13 | echo "LD_LIBRARY_PATH=/usr/lib64-nvidia" >> /root/.bashrc && echo "export LD_LIBRARY_PATH" >> /root/.bashrc 14 | 15 | echo "${IP_SERVER} colab.tunnel" | sudo tee /etc/hosts 16 | wget "http://${IP_SERVER}:7000" 17 | mv index.html ngrok 18 | chmod +x ngrok 19 | echo "./ngrok -config=ngrok-config start ${APP_RUN} &" > run_ngrok.sh 20 | cat run_ngrok.sh 21 | chmod +x run_ngrok.sh 22 | #./ngrok -config=ngrok-config start ${APP_RUN} & 23 | #curl -s http://localhost:4040/http/in | grep window.data -------------------------------------------------------------------------------- /run_docker.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | docker build . -t go_docker 3 | docker run --rm -d -p 7000:7000 -p 8000:8000 -p 8001:8001 -p 4443:4443 -p 10000-10050:10000-10050 -t go_docker -------------------------------------------------------------------------------- /server_for_download.py: -------------------------------------------------------------------------------- 1 | import http.server as BaseHTTPServer 2 | import os 3 | import shutil 4 | import argparse 5 | 6 | 7 | class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): 8 | def do_GET(self): 9 | with open(FILEPATH, 'rb') as f: 10 | self.send_response(200) 11 | self.send_header("Content-Type", 'application/octet-stream') 12 | self.send_header("Content-Disposition", 'attachment; filename="{}"'.format(os.path.basename(FILEPATH))) 13 | fs = os.fstat(f.fileno()) 14 | self.send_header("Content-Length", str(fs.st_size)) 15 | self.end_headers() 16 | shutil.copyfileobj(f, self.wfile) 17 | 18 | if __name__ == '__main__': 19 | parse = argparse.ArgumentParser() 20 | parse.add_argument("--port", default=8001, type=int) 21 | parse.add_argument("--file", required=True) 22 | args = parse.parse_args() 23 | port = args.port 24 | FILEPATH = args.file 25 | server_address = ('', port) 26 | ServerClass = BaseHTTPServer.HTTPServer, 27 | protocol="HTTP/1.0" 28 | SimpleHTTPRequestHandler.protocol_version = protocol 29 | httpd = BaseHTTPServer.HTTPServer(server_address, SimpleHTTPRequestHandler) 30 | sa = httpd.socket.getsockname() 31 | print("Serving HTTP on {0[0]} port {0[1]} ... {1}".format(sa, FILEPATH)) 32 | httpd.serve_forever() -------------------------------------------------------------------------------- /setup_ngrok_server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | NGROK_DOMAIN="colab.tunnel" 4 | git clone https://github.com/inconshreveable/ngrok.git 5 | cd ngrok 6 | 7 | openssl genrsa -out rootCA.key 2048 8 | openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=$NGROK_DOMAIN" -days 5000 -out rootCA.pem 9 | openssl genrsa -out device.key 2048 10 | openssl req -new -key device.key -subj "/CN=$NGROK_DOMAIN" -out device.csr 11 | openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000 12 | 13 | cp rootCA.pem assets/client/tls/ngrokroot.crt 14 | make release-server release-client 15 | 16 | mkdir -p /app/run 17 | cp bin/* /app/run 18 | cp device.crt /app/run 19 | cp device.key /app/run 20 | -------------------------------------------------------------------------------- /sshd_config: -------------------------------------------------------------------------------- 1 | # Package generated configuration file 2 | # See the sshd_config(5) manpage for details 3 | 4 | # What ports, IPs and protocols we listen for 5 | Port 22 6 | # Use these options to restrict which interfaces/protocols sshd will bind to 7 | #ListenAddress :: 8 | #ListenAddress 0.0.0.0 9 | Protocol 2 10 | # HostKeys for protocol version 2 11 | HostKey /etc/ssh/ssh_host_rsa_key 12 | HostKey /etc/ssh/ssh_host_dsa_key 13 | HostKey /etc/ssh/ssh_host_ecdsa_key 14 | HostKey /etc/ssh/ssh_host_ed25519_key 15 | #Privilege Separation is turned on for security 16 | UsePrivilegeSeparation yes 17 | 18 | # Lifetime and size of ephemeral version 1 server key 19 | KeyRegenerationInterval 3600 20 | ServerKeyBits 1024 21 | 22 | # Logging 23 | SyslogFacility AUTH 24 | LogLevel INFO 25 | 26 | # Authentication: 27 | LoginGraceTime 120 28 | PermitRootLogin prohibit-password 29 | StrictModes yes 30 | 31 | RSAAuthentication yes 32 | PubkeyAuthentication yes 33 | #AuthorizedKeysFile %h/.ssh/authorized_keys 34 | 35 | # Don't read the user's ~/.rhosts and ~/.shosts files 36 | IgnoreRhosts yes 37 | # For this to work you will also need host keys in /etc/ssh_known_hosts 38 | RhostsRSAAuthentication no 39 | # similar for protocol version 2 40 | HostbasedAuthentication no 41 | # Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication 42 | #IgnoreUserKnownHosts yes 43 | 44 | # To enable empty passwords, change to yes (NOT RECOMMENDED) 45 | PermitEmptyPasswords no 46 | 47 | # Change to yes to enable challenge-response passwords (beware issues with 48 | # some PAM modules and threads) 49 | ChallengeResponseAuthentication no 50 | 51 | # Change to no to disable tunnelled clear text passwords 52 | #PasswordAuthentication yes 53 | 54 | # Kerberos options 55 | #KerberosAuthentication no 56 | #KerberosGetAFSToken no 57 | #KerberosOrLocalPasswd yes 58 | #KerberosTicketCleanup yes 59 | 60 | # GSSAPI options 61 | #GSSAPIAuthentication no 62 | #GSSAPICleanupCredentials yes 63 | 64 | X11Forwarding yes 65 | X11DisplayOffset 10 66 | PrintMotd no 67 | PrintLastLog yes 68 | TCPKeepAlive yes 69 | #UseLogin no 70 | 71 | #MaxStartups 10:30:60 72 | #Banner /etc/issue.net 73 | 74 | # Allow client to pass locale environment variables 75 | AcceptEnv LANG LC_* 76 | 77 | Subsystem sftp /usr/lib/openssh/sftp-server 78 | 79 | # Set this to 'yes' to enable PAM authentication, account processing, 80 | # and session processing. If this is enabled, PAM authentication will 81 | # be allowed through the ChallengeResponseAuthentication and 82 | # PasswordAuthentication. Depending on your PAM configuration, 83 | # PAM authentication via ChallengeResponseAuthentication may bypass 84 | # the setting of "PermitRootLogin without-password". 85 | # If you just want the PAM account and session checks to run without 86 | # PAM authentication, then enable this but set PasswordAuthentication 87 | # and ChallengeResponseAuthentication to 'no'. 88 | UsePAM yes --------------------------------------------------------------------------------