Back to articles
DevOps & Systems

Comprehensive Guide to Setting Up Git and Remote Development with Code Server on a Dedicated VPS

A detailed guide on setting up Git and Code Server on a dedicated VPS, covering installation, configuration, security, and testing for remote development.

DPTCloud Engineering4 min read
Comprehensive Guide to Setting Up Git and Remote Development with Code Server on a Dedicated VPS

Image credit: TerriC · Pixabay Content License

Introduction

Setting up an effective remote development environment is essential for developers working independently or in distributed teams. With Code Server, you can access a full IDE directly through a web browser, just like working on a personal computer. Combined with Git, you can manage source code professionally and synchronize across multiple devices. This guide provides a detailed walkthrough of setting up Git and Code Server on a dedicated VPS, ensuring security, performance, and scalability.

Requirements and Preparation

Before starting, ensure you have:

  • A dedicated VPS (NVMe Cloud VPS or Dedicated Server) with Ubuntu 22.04 or Debian 11.
  • Root or sudo access on the VPS.
  • A stable internet connection.
  • A domain name or hostname for accessing Code Server (optional but recommended).

Setting Up Git on the VPS

Git is the most popular version control tool. Install Git on the VPS with the following commands:

sudo apt update
sudo apt install git -y

After installation, configure your user information:

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Verify the installation by running:

git --version

Installing and Configuring Code Server

Code Server is an open-source version of Visual Studio Code running on a server. Install it using the following command:

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

After installation, start the service:

code-server --bind-addr 0.0.0.0:8080

To run Code Server as a service, create a systemd service file:

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

Add the following content:

[Unit]
Description=Code Server
After=network.target

[Service]
Type=simple
User=your_username
ExecStart=/usr/bin/code-server --bind-addr 0.0.0.0:8080 --auth password --password your_password
Restart=always

[Install]
WantedBy=multi-user.target

Replace your_username and your_password with your details. Then start the service:

sudo systemctl daemon-reload
sudo systemctl enable code-server
sudo systemctl start code-server

Security and Secure Access

To secure Code Server, use Nginx as a reverse proxy and HTTPS:

sudo apt install nginx -y
sudo systemctl enable nginx
sudo systemctl start nginx

Create an Nginx configuration file:

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

Add the following content:

server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://localhost:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Enable the configuration:

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

Use Let's Encrypt to obtain an SSL certificate:

sudo apt install certbot -y
sudo certbot certonly --nginx -d your-domain.com

Testing and Verification

Access https://your-domain.com to verify Code Server is running. Log in with your configured username and password. Create a new folder, add an index.html file, and verify you can edit and save code.

To test Git, initialize a new repository:

git init my-project
cd my-project
echo "# My Project" > README.md
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/your-username/my-project.git
git push -u origin main

Troubleshooting

  • Code Server fails to start: Check logs with journalctl -u code-server -n 50.
  • Cannot access via Nginx: Verify Nginx configuration and firewall (UFW).
  • Git push fails: Check permissions and SSL certificates.

References

DPTCloud Tier III Infrastructure

Recommended NVMe Cloud VPS Plans to Deploy This Setup

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02

VPS-2E

94.600 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 2 GB
  • SSD: 30 GB NVMe
ECO · vn-02Recommended

VPS-3E

170.500 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 4 GB
  • SSD: 50 GB NVMe
BASIC · vn-01Recommended

VPS-05

457.600 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478