How to install Visual Studio Code Server on Debian 10

How to install Visual Studio Code Server on Debian 10

The code server is a Visual Studio (VS) code version that can be executed remotely on the server and accessed through a web browser. It makes it possible to create and run a consistent development environment that can be accessed anytime, anywhere.

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

prerequisites

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

What we will do:

  • Create a new user
  • Download code server
  • Set up the code server as a system service
  • Generate SSL Letsencrypt
  • Set Nginx as a reverse proxy for the 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 run under this user.

Use the following command to create a new user named “code”.

useradd -m -s /bin/bash codepasswd code

Now, enter the password for the user’s “code”, and a new user has been created to run the code server.

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 use the following wget command to download the code server source code.

su - codewget https://github.com/cdr/code-server/releases/download/3.0.0/code-server-3.0.0-linux-x86_64.tar.gz

Extract the source code and rename the directory to “bin /”.

tar -xf code-server-3.0.0-linux-x86_64.tar.gzmv code-server-*/ bin/

Now, use the “code server” binary as an executable file and create a new “data” directory to store the code server configuration.

chmod +x bin/code-servermkdir -p ~/data

As a result, the source code of the code server has been downloaded and we are ready for the next stage.

Unzip the file

Step 3-Set the code server as SysteSUBMITmd service

After downloading the source code of the code server, we set up the code server as a system service.

Now back to the root user, or if you have root sudo privileges, run the sudo command below.

sudo su

Now go to the “/ etc / systemd / system” directory and use the vim editor to create a new service file “code-server.service”.

cd /etc/systemd/system/vim code-server.service

change”Environment = password = …‘Options (use your own password) and paste the configuration.

[Unit]Description=code-serverAfter=nginx.service[Service]User=codeWorkingDirectory=/home/codeEnvironment=PASSWORD=hakasecodeservExecStart=/home/code/bin/code-server --host 127.0.0.1 --user-data-dir /home/code/data --auth passwordRestart=always[Install]WantedBy=multi-user.target

Save and close.

Next, use the following systemctl command to reload the systemd manager.

systemctl daemon-reload

Start the code server service and add it to the system boot.

systemctl start code-serversystemctl enable code-server

Create System Service

The code server is up and running, please check it with the following command.

netstat -plntusystemctl status code-server

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

Check service status

Step 4-Generate SSL Letsencrypt

In this step, we will use the certbot tool to generate SSL letencrypt to protect the code server.

Use the following apt command to install the certbot tool.

sudo apt install certbot -y

After the installation is complete, please use the following certbot command to generate SSL letencrypt.

certbot certonly --standalone --agree-tos -m [email protected] -d code.hakase-labs.io

After completion, your certificate will be located in the “/etc/letsencrypt/live/code.hakase-labs.io/” directory.

ls -lah /etc/letsencrypt/live/code.hakase-labs.io/

Now, you have generated SSL Letsencrypt to use the certbot tool to protect the installation of the code server.

Step 5-Set up Nginx as a reverse proxy

In this step, we install the Nginx web server to the Debian system. It will be used as a reverse proxy for code servers running on the default port “8080”.

Use the following apt command to install the Nginx package.

sudo apt install nginx -y

After the installation is complete, go to the “/ etc / nginx / sites-available” directory and use the vim editor to create a new virtual host configuration “code server”.

cd /etc/nginx/sites-available/vim code-server

Change the domain name and SSL path yourself, and 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 https://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 are no errors.

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 the code server has been completed, and the code server can now be accessed through a web browser.

Nginx configuration

Step 6-Test the code server

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

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

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

Login code server GUI

Enter the password and click “submit‘Button.

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

Code-OSS

As a result, you have successfully installed the code server on Debian Buster 10 using Nginx reverse proxy and SSL Letsencrypt.

Source

Related Posts