VS Code is the code editor of choice for many. However, when we want to do quick edits on some files on a remote server, and there is no access to VS Code, it becomes a bit of a hassle.

Also, sometimes VS Code is not accessible on a particular system and we might still want to be able to access local files and folders using VS Code.

This is where code-server is invaluable.

Installation

Initially, before installing code-server it’s helpful to see if all requirements are met.

To do this, run

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

The output of this will tell if everything is fine.

To install code-server, run

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

Configuration

The configuration file is in

~/.config/code-server/config.yaml

This file should be created, if not already there.

The contents of this file should be

bind-addr: 127.0.0.1:1234
auth: password
password: <Your complex password>
cert: false

Choose the port according to what is available. The password should be complex e.g. at least 12 characters long with a mix of alphabets, numbers and special characters.

Nginx configuration

Since we want to run code-server on https behind Nginx, the nginx configuration file can be

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name     code.yourdomain.com;
    server_tokens off;

    ssl_certificate <path to ssl cert>;
    ssl_certificate_key <path to ssl key>;

    error_log       /var/log/nginx/vs-code-server_error.log;
    access_log      /var/log/nginx/vs-code-server_access.log;

    location / {
      proxy_pass http://localhost:1234/;
      proxy_set_header Host $http_host;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection upgrade;
      proxy_set_header Accept-Encoding gzip;
    }
}

After saving this file, ensure nginx is tested

nginx -t

and reloaded

nginx -s reload

Running code-server

If code-server needs to be run only occasionally, the command is

code-server

This runs it in the foreground and Ctrl+C stops it.

If it has to be run continuously in the background and should also restart on reboot, the command is

sudo systemctl enable --now code-server@$USER

Test it from the browser

Now that both code-server is running and nginx has been reloaded, going to https://code.yourdomain.com should show VS Code running in the browser.

Uninstall code-server

To uninstall code-server completely, delete everything in the /usr/lib/code-server folder.

Kill all code-server processes using

kill -9 code-server