VScode everywhere

Sebastián Vidal Aedo
3 min readFeb 8, 2023

--

How to use full vscode from anywhere? the first answer would be https://vscode.dev/, but it is not “complete”. The option to have a full vscode and access it from anywhere is to use vscode server (even from a tablet or cell phone).

For this POC I will use an aws instance, where to install the vscode-server (I will assume that the EC2 instance already exists).

Install vscode-sever

Inside our instance we execute:

wget https://github.com/cdr/code-server/releases/download/3.1.1/code-server-3.1.1-linux-x86_64.tar.gz
tar -xvzf code-server-3.1.1-linux-x86_64.tar.gz
sudo mv code-server-3.1.1-linux-x86_64 /opt/code-server
sudo ln -s /opt/code-server/code-server /usr/local/bin/code-server

Configure

We edit the vscode-server configuration

sudo nano /etc/code-server.conf

leaving the following content

#!/bin/sh

# Start code-server
/usr/local/bin/code-server - auth password - port 8080

with this we tell it that we will use a password and that vscode-server will be exposed through port 8080.

Start

We can modify the “start” of the server, in order to indicate certain parameters (like the password). For this we edit the file code-server.service (before we give it execution permissions)

sudo chmod +x /etc/code-server.conf
sudo nano /etc/systemd/system/code-server.service

inside code-server.service we leave the following

[Unit]
Description=CodeServer

[service]
Environment=PASSWORD=yoour_custom_password_to_access_here
ExecStart=/etc/code-server.conf
restart=always
User=your_user

[Install]
WantedBy=multi-user.target

Service

We give execution permissions

sudo chmod +x /etc/systemd/system/code-server.service

Start and status

sudo systemctl start code-server
sudo systemctl enable code-server
sudo systemctl status code-server

The Server: Nginx

Install

sudo apt install nginx

Edit config file

sudo nano /etc/nginx/sites-available/vscode-server

Update content to:

server { 
listen 80;
server_name ip.number.your.ec2;

location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}

Enabled and restart nginx

sudo ln -s /etc/nginx/sites-available/vscode-server /etc/nginx/sites-enabled/ 
sudo systemctl restart nginx
sudo nginx -t

Then, we access the ip of our EC two and we will see a login

With the password we set in code-server.service we can access and that’s all!

Extra

If you want to use extensions that use specific ports, for example LiveServer, you must open the port in your instance rules.

--

--

No responses yet