• 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 codeNow 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/r...-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.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 ~/dataAs a result, the code-server source code has been downloaded, and we're ready for the next stage.

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 suNow 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.serviceChange 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=hak asecodeserv
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.targetSave and close.
Advertisements

Next, reload the systemd manager using the systemctl command below.
systemctl daemon-reloadStart the code-server service and add it to the system boot.
systemctl start code-server
systemctl enable code-server
The code-server is up and running, check it using the following command.
netstat -plntu
systemctl status code-serverAs a result, the code-server is up and running as a systemd service on the Debian Buster 10.
Advertisements


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 -yOnce the installation is complete, generate the SSL letsencrypt using the certbot command below.
certbot certonly --standalone --agree-tos -m myemail@gmail.com -d code.hakase-labs.ioOnce 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 -yOnce 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-serverChange the domain name and SSL path with your own, then paste the configuration into it.
Advertisements

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 -tNow restart the Nginx service.
systemctl restart nginxAs 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.

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.

Type your password and click the 'SUBMIT' button.