Skip to content

Instantly share code, notes, and snippets.

@kathoef
Last active July 7, 2022 10:09
Show Gist options
  • Save kathoef/2d85d78c17ff93d711c8a197050cdd0b to your computer and use it in GitHub Desktop.
Save kathoef/2d85d78c17ff93d711c8a197050cdd0b to your computer and use it in GitHub Desktop.
VS Code server with token password and HTTPS

Remote machine,

$ ssh user@host
$ mkdir -p $HOME/vscodeserver
$ cd $HOME/vscodeserver
$ bash install.sh
$ bash start.sh
c773621a-f86f-4f44-99a8-ef149521765a
[2022-04-14T10:41:07.120Z] info  code-server 4.2.0 693b1fac04524bb0e0cfbb93afc85702263329bb
[2022-04-14T10:41:07.121Z] info  Using user-data-dir ~/vscodeserver/user-data-dir
[2022-04-14T10:41:07.156Z] info  Using config file ~/.config/code-server/config.yaml
[2022-04-14T10:41:07.156Z] info  HTTPS server listening on https://127.0.0.1:8080/ 
[2022-04-14T10:41:07.156Z] info    - Authentication is enabled
[2022-04-14T10:41:07.156Z] info      - Using password from $PASSWORD
[2022-04-14T10:41:07.156Z] info    - Using certificate for HTTPS: ~/vscodeserver/mycert.pem

Local machine,

$ ssh -L 127.0.0.1:8080:127.0.0.1:8080 -N user@host

Then open https://localhost:8080/ in your browser.

VS Code Server docs,

wget https://github.com/coder/code-server/releases/download/v4.2.0/code-server-4.2.0-linux-amd64.tar.gz
tar -xvf code-server-4.2.0-linux-amd64.tar.gz
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mykey.key -out mycert.pem
#!/bin/bash
export PASSWORD=$(uuidgen); echo $PASSWORD
$HOME/vscodeserver/code-server-4.2.0-linux-amd64/bin/code-server --cert $PWD/mycert.pem --cert-key $PWD/mykey.key \
--user-data-dir $PWD/user-data-dir --extensions-dir $PWD/extensions-dir
@kathoef
Copy link
Author

kathoef commented Jul 7, 2022

If Chrome refuses to connect to VS Code Server with the self-signed certificates use here, you may, as a workaround, want to use the 'thisisunsafe'-hack discussed here. Or better specify and use "trusted" certificates during VS Code Server start-up, for MacOS e.g. via generating these via your Keychain beforehand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment