4
4
5
5
- [ 1. Acquire a remote machine] ( #1-acquire-a-remote-machine )
6
6
- [ Requirements] ( #requirements )
7
- - [ Google Cloud Platform ] ( #google-cloud-platform )
7
+ - [ Google Cloud] ( #google-cloud )
8
8
- [ 2. Install code-server] ( #2-install-code-server )
9
9
- [ 3. Expose code-server] ( #3-expose-code-server )
10
10
- [ SSH forwarding] ( #ssh-forwarding )
18
18
This guide demonstrates how to setup and use code-server.
19
19
To reiterate, code-server lets you run VS Code on a remote server and then access it via a browser.
20
20
21
- See the [ README] ( ../README.md ) for a general overview and the [ FAQ] ( ./FAQ.md ) for further user docs.
21
+ See [ README.md ] ( ../README.md ) for a general overview and [ FAQ.md ] ( ./FAQ.md ) for further user docs.
22
22
23
23
We'll walk you through acquiring a remote machine to run code-server on and then exposing ` code-server ` so you can
24
- easily access it.
24
+ securely access it.
25
25
26
26
## 1. Acquire a remote machine
27
27
@@ -35,9 +35,9 @@ For a good experience, we recommend at least:
35
35
- 1 GB of RAM
36
36
- 2 cores
37
37
38
- You can use whatever linux distribution floats your boat but in this guide we assume Debian.
38
+ You can use whatever linux distribution floats your boat but in this guide we assume Debian on Google Cloud .
39
39
40
- ### Google Cloud Platform
40
+ ### Google Cloud
41
41
42
42
For demonstration purposes, this guide assumes you're using a VM on GCP but you should be
43
43
able to easily use any machine or VM provider.
@@ -47,19 +47,24 @@ free trial.
47
47
48
48
Once you've signed up and created a GCP project, create a new Compute Engine VM Instance.
49
49
50
- 1 . Navigate to ` Compute Engine -> VM Instances ` on the sidebar
51
- 2 . Now click ` Create Instance ` to create a new instance
52
- 3 . Choose the region closest to you based on [ gcping.com] ( http://www.gcping.com )
53
- 4 . Name it whatever you want
54
- 5 . Any zone is fine
55
- 6 . We'd recommend a ` e2-standard-2 ` instance from the E2 series and General-purpose family
56
- - Add more vCPUs and memory as you prefer, you can edit after creating the instance as well
50
+ 1 . Navigate to ` Compute Engine -> VM Instances ` on the sidebar.
51
+ 2 . Now click ` Create Instance ` to create a new instance.
52
+ 3 . Name it whatever you want.
53
+ 4 . Choose the region closest to you based on [ gcping.com] ( http://www.gcping.com ) .
54
+ 5 . Any zone is fine.
55
+ 6 . We'd recommend a ` E2 ` series instance from the General-purpose family.
56
+ - Change the type to custom and set at least 2 cores and 2 GB of ram.
57
+ - Add more vCPUs and memory as you prefer, you can edit after creating the instance as well.
57
58
- https://cloud.google.com/compute/docs/machine-types#general_purpose
58
- 7 . We highly recommend switching the persistent disk to a SSD of at least 32 GB
59
+ 7 . We highly recommend switching the persistent disk to a SSD of at least 32 GB.
60
+ - Click ` Change ` under ` Boot Disk ` and change the type to ` SSD Persistent Disk ` and the size
61
+ to ` 32 ` .
62
+ - You can always grow your disk later.
63
+ - The default OS of Debian 10 is fine.
59
64
8 . Navigate to ` Networking -> Network interfaces ` and edit the existing interface
60
- to use a static external IP
61
- - Click done to save network interface changes
62
- 9 . If you do not have a [ project wide SSH key] ( https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys#project-wide ) , navigate to ` Security - > SSH Keys ` and add your public key there
65
+ to use a static external IP.
66
+ - Click done to save network interface changes.
67
+ 9 . If you do not have a [ project wide SSH key] ( https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys#project-wide ) , navigate to ` Security - > SSH Keys ` and add your public key there.
63
68
10 . Click create!
64
69
65
70
Remember, you can shutdown your server when not in use to lower costs.
@@ -82,10 +87,10 @@ systemctl --user enable --now code-server
82
87
83
88
## 3. Expose code-server
84
89
85
- There are several approaches to operating and exposing code-server.
90
+ ** Never** , ** ever** expose ` code-server ` directly to the internet without some form of authentication
91
+ and encryption as someone can completely takeover your machine with the terminal.
86
92
87
- Since you can gain access to a terminal from within code-server, ** never** , ** ever**
88
- expose it directly to the internet without some form of authentication and encryption!
93
+ There are several approaches to securely operating and exposing code-server.
89
94
90
95
By default, code-server will enable password authentication which will
91
96
require you to copy the password from the code-server config file to login. You
@@ -99,17 +104,9 @@ We highly recommend this approach for not requiring any additional setup, you ju
99
104
SSH server on your remote machine. The downside is you won't be able to access ` code-server `
100
105
without an SSH client like an iPad. If that's important to you, skip to [ Let's Encrypt] ( #lets-encrypt ) .
101
106
102
- Recommended reading: https://help.ubuntu.com/community/SSH/OpenSSH/PortForwarding
107
+ Recommended reading: https://help.ubuntu.com/community/SSH/OpenSSH/PortForwarding .
103
108
104
- ``` bash
105
- # -N disables executing a remote shell
106
- ssh -N -L 8080:127.0.0.1:8080 < instance-ip>
107
- ```
108
-
109
- As long as this command hasn't exited, that means any request on local port 8080 goes to your
110
- instance at ` 127.0.0.1:8080 ` which is where code-server is running.
111
-
112
- Next ssh into your instance and edit your code-server config file to disable password authentication.
109
+ First, ssh into your instance and edit your code-server config file to disable password authentication.
113
110
114
111
``` bash
115
112
# Replaces "auth: password" with "auth: none" in the code-server config.
@@ -122,6 +119,13 @@ Restart code-server with (assuming you followed the guide):
122
119
systemctl --user restart code-server
123
120
```
124
121
122
+ Now forward local port 8080 to ` 127.0.0.1:8080 ` on the remote instance.
123
+
124
+ ``` bash
125
+ # -N disables executing a remote shell
126
+ ssh -N -L 8080:127.0.0.1:8080 < instance-ip>
127
+ ```
128
+
125
129
Now if you access http://127.0.0.1:8080 locally, you should see code-server!
126
130
127
131
If you want to make the SSH port forwarding persistent we recommend using
@@ -130,7 +134,7 @@ If you want to make the SSH port forwarding persistent we recommend using
130
134
```
131
135
# Same as the above SSH command but runs in the background continously.
132
136
# Add `mutagen daemon start` to your ~/.bashrc to start the mutagen daemon when you open a shell.
133
- mutagen forward create --help -n =code-server tcp:127.0.0.1:8080 <instance-ip>:tcp:127.0.0.1:8080
137
+ mutagen forward create --name =code-server tcp:127.0.0.1:8080 <instance-ip>:tcp:127.0.0.1:8080
134
138
```
135
139
136
140
We also recommend adding the following lines to your ` ~/.ssh/config ` to quickly detect bricked SSH connections:
@@ -149,14 +153,14 @@ and sign commits without copying your keys onto the instance.
149
153
150
154
### Let's Encrypt
151
155
152
- Let's Encrypt is a great option if you want to access code-server on an iPad or just want password
153
- based authentication . This does require that the remote machine is exposed to the internet.
156
+ [ Let's Encrypt] ( https://letsencrypt.org ) is a great option if you want to access code-server on an iPad
157
+ or do not want to use SSH forwarding . This does require that the remote machine is exposed to the internet.
154
158
155
159
Assuming you have been following the guide, edit your instance and checkmark the allow HTTP/HTTPS traffic options.
156
160
157
- 1 . You'll need to buy a domain name. We recommend [ Google Domains] ( https://domains.google.com )
158
- 2 . Add an A record to your domain with your instance's IP
159
- 3 . Install caddy https://caddyserver.com/docs/download#debian-ubuntu-raspbian
161
+ 1 . You'll need to buy a domain name. We recommend [ Google Domains] ( https://domains.google.com ) .
162
+ 2 . Add an A record to your domain with your instance's IP.
163
+ 3 . Install caddy https://caddyserver.com/docs/download#debian-ubuntu-raspbian .
160
164
161
165
``` bash
162
166
echo " deb [trusted=yes] https://apt.fury.io/caddy/ /" \
@@ -189,11 +193,15 @@ the dependency on caddy.
189
193
** note:** Self signed certificates do not work with iPad and will cause a blank page. You'll
190
194
have to use [ Let's Encrypt] ( #lets-encrypt ) instead.
191
195
192
- Recommended reading: https://security.stackexchange.com/a/8112
196
+ Recommended reading: https://security.stackexchange.com/a/8112 .
193
197
194
198
We recommend this as a last resort as self signed certificates do not work with iPads and can
195
199
cause other bizarre issues. Not to mention all the warnings when you access code-server.
196
- Only use this if you do not want to buy a domain or cannot expose the remote machine to the internet.
200
+ Only use this if:
201
+
202
+ 1 . You do not want to buy a domain.
203
+ 2 . You cannot expose the remote machine to the internet.
204
+ 3 . You do not want to use SSH forwarding.
197
205
198
206
ssh into your instance and edit your code-server config file to use a randomly generated self signed certificate:
199
207
@@ -217,8 +225,8 @@ Edit your instance and checkmark the allow HTTPS traffic option.
217
225
Visit ` https://<your-instance-ip> ` to access code-server.
218
226
You'll get a warning when accessing but if you click through you should be good.
219
227
220
- You can also use [ mkcert] ( https://mkcert.dev ) to create a self signed certificate trusted by your
221
- OS to avoid the warnings and then pass it to code-server via the ` cert ` and ` cert-key ` config
228
+ To avoid the warnings, you can use [ mkcert] ( https://mkcert.dev ) to create a self signed certificate
229
+ trusted by your OS and then pass it into code-server via the ` cert ` and ` cert-key ` config
222
230
fields.
223
231
224
232
### Change the password?
@@ -234,4 +242,4 @@ systemctl --user restart code-server
234
242
235
243
If you're working on a web service and want to access it locally, code-server can proxy it for you.
236
244
237
- See the [ FAQ] ( https://github.com/cdr/code-server/blob/master/doc/FAQ.md#how-do-i-securely-access-web-services ) .
245
+ See [ FAQ.md ] ( https://github.com/cdr/code-server/blob/master/doc/FAQ.md#how-do-i-securely-access-web-services ) .
0 commit comments