How to have your own online VSCode Server

I’ve found this very interesting, having my online VSCode accessible from any laptop / tablet within my network. Bellow I will describe the steps I took to make that possible:

To install a VS Code server, we will use code-server by coder. To install it, run the following command:

curl -fsSL https://code-server.dev/install.sh | sh

This is the output:

marius@desktop1:~$ curl -fsSL https://code-server.dev/install.sh | sh
Linux Mint 20.1
Unsupported package manager.
Installing standalone release archive v3.10.2 from GitHub releases.

+ mkdir -p ~/.cache/code-server
+ curl -#fL -o ~/.cache/code-server/code-server-3.10.2-linux-amd64.tar.gz.incomplete -C - https://github.com/cdr/code-server/releases/download/v3.10.2/code-server-3.10.2-linux-amd64.tar.gz
######################################################################## 100.0%##O=#  #                                                                      
+ mv ~/.cache/code-server/code-server-3.10.2-linux-amd64.tar.gz.incomplete ~/.cache/code-server/code-server-3.10.2-linux-amd64.tar.gz
+ mkdir -p ~/.local/lib ~/.local/bin
+ tar -C ~/.local/lib -xzf ~/.cache/code-server/code-server-3.10.2-linux-amd64.tar.gz
+ mv -f ~/.local/lib/code-server-3.10.2-linux-amd64 ~/.local/lib/code-server-3.10.2
+ ln -fs ~/.local/lib/code-server-3.10.2/bin/code-server ~/.local/bin/code-server

Standalone release has been installed into ~/.local/lib/code-server-3.10.2
Please extend your path to use code-server:
  PATH="$HOME/.local/bin:$PATH"
Then you can run:
  code-server
marius@desktop1:~$ code-server
code-server: command not found
marius@desktop1:~$ PATH="$HOME/.local/bin:$PATH"
marius@desktop1:~$ export PATH
marius@desktop1:~$ code-server
[2021-06-15T11:07:09.232Z] info  Wrote default config file to ~/.config/code-server/config.yaml
[2021-06-15T11:07:09.637Z] info  code-server 3.10.2 387b12ef4ca404ffd39d84834e1f0776e9e3c005
[2021-06-15T11:07:09.639Z] info  Using user-data-dir ~/.local/share/code-server
[2021-06-15T11:07:09.654Z] info  Using config file ~/.config/code-server/config.yaml
[2021-06-15T11:07:09.654Z] info  HTTP server listening on http://127.0.0.1:8080 
[2021-06-15T11:07:09.654Z] info    - Authentication is enabled
[2021-06-15T11:07:09.654Z] info      - Using password from ~/.config/code-server/config.yaml
[2021-06-15T11:07:09.654Z] info    - Not serving HTTPS 

The installation is very minimal and since this is used within my private network, I have not installed any certificates. I have changed the port from 8080 to 8181.

To make it a bit easier, I have created a service for code-server:

marius@desktop1:$ cat /etc/systemd/system/code-server.service 
[Unit]
Description=code-server
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
Environment=PASSWORD=< your own password from config file >
User=marius
Group=marius
ExecStart=/home/marius/.local/bin/code-server --bind-addr 127.0.0.1:8181 --user-data-dir  /home/marius/.local/share/code-server --auth password
Restart=always

[Install]
WantedBy=multi-user.target

marius@desktop1:/etc/systemd/system$ sudo systemctl start code-server
marius@desktop1:/etc/systemd/system$ sudo systemctl status code-server
● code-server.service - code-server
     Loaded: loaded (/etc/systemd/system/code-server.service; disabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-06-15 14:06:35 CEST; 5s ago
   Main PID: 104306 (node)
      Tasks: 22 (limit: 28689)
     Memory: 62.0M
     CGroup: /system.slice/code-server.service
             ├─104306 /home/marius/.local/lib/code-server-3.10.2/lib/node /home/marius/.local/lib/code-server-3.10.2 --bind-addr 127.0.0.1:8181 --user-data-dir /home/>
             └─104342 /home/marius/.local/lib/code-server-3.10.2/lib/node /home/marius/.local/lib/code-server-3.10.2 --bind-addr 127.0.0.1:8181 --user-data-dir /home/>

Jun 15 14:06:35 desktop1 systemd[1]: Started code-server.
Jun 15 14:06:35 desktop1 code-server[104342]: [2021-06-15T12:06:35.828Z] info  code-server 3.10.2 387b12ef4ca404ffd39d84834e1f0776e9e3c005
Jun 15 14:06:35 desktop1 code-server[104342]: [2021-06-15T12:06:35.829Z] info  Using user-data-dir /home/marius/.local/share/code-server
Jun 15 14:06:35 desktop1 code-server[104342]: [2021-06-15T12:06:35.844Z] info  Using config file ~/.config/code-server/config.yaml
Jun 15 14:06:35 desktop1 code-server[104342]: [2021-06-15T12:06:35.844Z] info  HTTP server listening on http://192.168.4.78:8181
Jun 15 14:06:35 desktop1 code-server[104342]: [2021-06-15T12:06:35.844Z] info    - Authentication is enabled
Jun 15 14:06:35 desktop1 code-server[104342]: [2021-06-15T12:06:35.844Z] info      - Using password from $PASSWORD
Jun 15 14:06:35 desktop1 code-server[104342]: [2021-06-15T12:06:35.844Z] info    - Not serving HTTPS

Let’s go to the webpage now ( use the password from the configuration file):

Now we have a VSCode accessible from any device within my network 🙂

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.