Tutorial-9122023

How to Install Visual Studio Code Server on Debian 10

1 29

How to Install Visual Studio Code Server on Debian 10

Code server is a Visual Studio (VS) code version that can be executed remotely on the server and accessed via a web browser. It enables the creation and operation of a consistent development environment that can be accessed anytime, anywhere.

In this tutorial we show you how to install the code server on the Debian Buster 10. We will install and configure the code server using Nginx as a reverse proxy, secure it with SSL Letsencrypt and enable code server basic authentication.

Prerequisites

For this guide, we will install the code-server on the latest Debian 10 with 2GB of memory, 25GB free disk space, and 2 CPUs.

What we will do:

  • Create a New User
  • Download Code-Server
  • Setup Code-Server as a Systemd Service
  • Generate SSL Letsencrypt
  • Setup Nginx as a Reverse Proxy for Code-Server
  • Testing

Step 1 – Create a New Linux User

First, we will create a new user on the Debian system. The code-server will be running under that user.

Create a new user named ‘code’ using the command below.
useradd -m -s /bin/bash code
passwd code

Now type the password for user ‘code’, and the new user for running code-server has been created.

Step 2 – Download Visual Studio Code-Server from GitHub

In this step, we will download the code-server source code from GitHub.

Log in to the user ‘code’ and download the code-server source code using the wget command below.
su - code
wget https://github.com/cdr/code-server/releases/download/3.0.0/code-server-3.0.0-linux-x86_64.tar.gz

Add user and download Visual Studio Code

Extract the source code and rename the directory to ‘bin/’.
tar -xf code-server-3.0.0-linux-x86_64.tar.gz
mv code-server-*/ bin/

Now make the ‘code-server’ binary file as an executable and create a new ‘data’ directory for storing code-server configurations.
chmod +x bin/code-server
mkdir -p ~/data

As a result, the code-server source code has been downloaded, and we’re ready for the next stage.

Unpack the archive

Step 3 – Setup Code-Server as a SysteSUBMITmd Service

After downloading the code-server source code, we will set up the code-server as a systemd service.

Now back to the root user or if you’ve got the root sudo privileges, run the sudo command below.
sudo su

Now go to the ‘/etc/systemd/system’ directory and create a new service file ‘code-server.service’ using vim editor.
cd /etc/systemd/system/
vim code-server.service

Change the ‘hakasecodeserv’ on the ‘Environment=PASSWORD=…‘ option with your own password and paste the configuration.
[Unit]Description=code-server
After=nginx.service

[Service]User=code
WorkingDirectory=/home/code
Environment=PASSWORD=hakasecodeserv
ExecStart=/home/code/bin/code-server --host 127.0.0.1 --user-data-dir /home/code/data --auth password
Restart=always

[Install]WantedBy=multi-user.target

Save and close.

Next, reload the systemd manager using the systemctl command below.
systemctl daemon-reload

Start the code-server service and add it to the system boot.
systemctl start code-server
systemctl enable code-server

Create systemd service

The code-server is up and running, check it using the following command.
netstat -plntu
systemctl status code-server

As a result, the code-server is up and running as a systemd service on the Debian Buster 10.

Check service status

Step 4 – Generate SSL Letsencrypt

In this step, we will generate the SSL letsencrypt using the certbot tool for securing the code-server.

Install the certbot tool using the apt command below.
sudo apt install certbot -y

Once the installation is complete, generate the SSL letsencrypt using the certbot command below.
certbot certonly --standalone --agree-tos -m [email protected] -d code.hakase-labs.io

Once it’s complete, your certificates will be located at the ‘/etc/letsencrypt/live/code.hakase-labs.io/’ directory.
ls -lah /etc/letsencrypt/live/code.hakase-labs.io/

Now you’ve generated the SSL Letsencrypt for securing the code-server installation using the certbot tool.

Step 5 – Setup Nginx as a Reverse Proxy

In this step, we will install the Nginx webserver to the Debian system. It will be used as a reverse proxy for the code-server that running on default port ‘8080’.

Install Nginx packages using the apt command below.
sudo apt install nginx -y

Once the installation is complete, go to the ‘/etc/nginx/sites-available’ directory and create a new virtual host configuration ‘code-server’ using vim editor.
cd /etc/nginx/sites-available/
vim code-server

Change the domain name and SSL path with your own, then paste the configuration into it.
server {
    listen 80;
    server_name code.hakase-labs.io;
    # enforce https
    return 301 https://$server_name:443$request_uri;
}

server {
    listen 443 ssl http2;
    server_name code.hakase-labs.io;

    ssl_certificate /etc/letsencrypt/live/code.hakase-labs.io/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/code.hakase-labs.io/privkey.pem;

    location / {
        proxy_pass http://127.0.0.1:8080/;
        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection upgrade;
        proxy_set_header Accept-Encoding gzip;
    }
}

Save and close.

Now activate the ‘code-server’ virtual host and check the Nginx configuration, and make sure there is no error.
ln -s /etc/nginx/sites-available/code-server /etc/nginx/sites-enabled/
nginx -t

Now restart the Nginx service.
systemctl restart nginx

As a result, the Nginx configuration as a reverse proxy for code-server has been completed, and the code-server is now accessible through your web browser.

Nginx configuration

Step 6 – Testing Code-server

Open your web browser and type the code-server URL installation. Mine is (replace the domain with your domain):

https://code.hakse-labs.io/

Now you will be redirected to secure HTTPS connection and you will be asked for the code-server password.

Log into code server GUI

Type your password and click the ‘SUBMIT‘ button.

Now you will get the Visual Code Studio Editor on your web browser.

Code - OSS

As a result, you’ve successfully installed the code-server on the Debian Buster 10 with Nginx reverse proxy and SSL Letsencrypt.

Đăng ký liền tay Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !

Add Comment

Click here to post a comment

Đăng ký liền tay
Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !