Skip to main content

Installing and Configuring code-server for Remote VS Code Access

36 views 3 min read read

Learn how to install and configure code-server to run VS Code in your browser, enabling remote access from any device.

Introduction

code-server is a powerful tool that allows you to run Visual Studio Code in your web browser, enabling remote development from any device. Whether you're working on a server, a low-power device like a Raspberry Pi, or simply want VS Code accessible from anywhere, code-server is a great solution.

🔹 Step 1: Installing code-server

Installation is straightforward and varies depending on your system.

1️⃣ Install on Linux (Ubuntu/Debian)

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

Once installed, start the server:

code-server

By default, it runs on http://localhost:8080 with a generated password.

2️⃣ Install on macOS

brew install code-server

3️⃣ Install on Windows (via WSL)

If you're using Windows, it's recommended to install code-server in WSL:

wget https://github.com/coder/code-server/releases/latest/download/code-server-linux-amd64.tar.gz
tar -xvzf code-server-linux-amd64.tar.gz
cd code-server-linux-amd64
./code-server

🔹 Step 2: Configuring code-server

After installation, you can configure code-server for better security and performance.

1️⃣ Changing the Default Port

By default, code-server runs on port 8080. You can change it by modifying the configuration file:

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

Update the port:

bind-addr: 0.0.0.0:9000

Restart the server:

code-server

2️⃣ Setting Up a Password

To secure your code-server , set a password:

export PASSWORD="your-secure-password"

Or update it in config.yaml :

auth: password
password: your-secure-password

3️⃣ Using a Custom Domain with HTTPS

If you're hosting code-server on a VPS, it's recommended to use a reverse proxy like Nginx with a free SSL certificate.

🔹 Install Nginx:

sudo apt install nginx

🔹 Configure the Proxy:

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

Add the following:


server {
    listen 80;
    server_name yourdomain.com;

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

Enable the site and restart Nginx:


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

🔹 Secure with Let's Encrypt:

sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com

🔹 Step 3: Running code-server as a Systemd Service

To keep code-server running in the background, create a systemd service:

1️⃣ Create the Service File

sudo nano /etc/systemd/system/code-server.service

Add:


[Unit]
Description=code-server
After=network.target

[Service]
User=your-user
ExecStart=/usr/bin/code-server --bind-addr 0.0.0.0:8080
Restart=always

[Install]
WantedBy=multi-user.target

2️⃣ Enable and Start the Service


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

🔹 Step 4: Accessing code-server Remotely

Now, you can access VS Code from any device by navigating to:

http://yourdomain.com

If you're using an SSH tunnel for local access:

ssh -L 8080:localhost:8080 your-user@your-server

Conclusion

With code-server , you can set up a fully remote VS Code environment accessible from any browser. By securing it with a password, domain, and SSL, you ensure a safe and seamless development experience.

Related Posts