Deploying a Programming Workspace on a Cloud Server: A Guide to Stable Multi-Device Access
This guide explains how to deploy a programming workspace on a cloud server for stable access from multiple devices. It covers server sizing, a dedicated service user, runtime verification, environment configuration, running the service with systemd, Nginx reverse proxying with HTTPS, firewall and SSH hardening, encrypted backups with restore drills, and common troubleshooting steps.
1. Prerequisites and Scope
Before you deploy, confirm the server specifications, domain name, and access scope.
Recommended server specifications:
- Light use by 1 to 3 people: 2 CPU cores, 4 GB RAM, and 40 GB disk. With 2 GB RAM, running several plugins and build tasks at once can easily run out of memory. When memory runs out, the Linux kernel terminates the process using the most memory, which shows up as interrupted pages or failed tasks.
- Concurrent use by multiple people, or frequent builds and dependency installs: at least 4 GB RAM, with disk space reserved based on project size.
- Operating system: Ubuntu 22.04 LTS.
For long-term use, bind the service to a domain name. This guide uses workspace.example.com as an example. Replace it with your own domain before you start. Then add an A record at your DNS provider that points to the server’s public IP address.
This guide suits personal long-term use and internal sharing within a small team. It is not suitable for the following scenarios: serving the public, handling highly sensitive data without audit capabilities, or running a server that no one maintains over the long term.
Before you start, confirm that the web-based terminal in your cloud console opens correctly. If the SSH configuration breaks, that terminal is your backup way in.
2. Creating a Dedicated User and Directories
First, update the system and install the base tools:
sudo apt updatesudo apt upgrade -ysudo apt install -y git curl nginx ufw
Create a system user that cannot log in, then set up the directories:
sudo useradd --system --create-home --shell /usr/sbin/nologin workspacesudo mkdir -p /srv/workspace/{app,data,logs,backup}sudo chown -R workspace:workspace /srv/workspacesudo chmod 750 /srv/workspace /srv/workspace/app /srv/workspace/logssudo chmod 700 /srv/workspace/data /srv/workspace/backup
The service user has no login permission. Even if the service process has a vulnerability, an attacker cannot gain administrator privileges on the system. Handle routine maintenance through your own account with sudo. Do not log in directly as root.
Verify that the permissions took effect:
ls -ld /srv/workspace /srv/workspace/*
3. Installing the Runtime and Verifying the Program
Install the Node.js version required by the project documentation. You can use the official binary package or the version manager that the project specifies. Do not run install scripts from unknown sources. After installation, check the versions and record the full path of node, which you need when you write the systemd service:
node --versionnpm --versioncommand -v node
Program files must come from the official repository or another trusted release channel. After downloading, verify the checksum. Extract the archive only after verification passes:
cd /tmpcurl -fLO https://OFFICIAL-DOMAIN/workspace-release.tar.gzcurl -fLO https://OFFICIAL-DOMAIN/workspace-release.tar.gz.sha256sha256sum -c workspace-release.tar.gz.sha256
Continue only if the output is OK. If it shows FAILED, delete the two files you just downloaded and download them again. This does not affect the program that is already installed.
After verification passes, extract the archive and install the dependencies. If the archive contains a top-level directory, keep --strip-components=1. Follow the project documentation for the dependency install command:
sudo tar -xzf workspace-release.tar.gz -C /srv/workspace/app --strip-components=1sudo chown -R workspace:workspace /srv/workspace/appcd /srv/workspace/appsudo -u workspace npm ci --omit=dev
4. Configuring Environment Variables
Store sensitive settings in a .env file with restricted permissions. Do not put them in code or commit them to the repository. Use the variable names defined in the project documentation:
sudo tee /srv/workspace/.env > /dev/null <<'EOF'APP_ENV=productionAPP_PORT=8080APP_HOST=127.0.0.1DATA_DIR=/srv/workspace/dataLOG_DIR=/srv/workspace/logsMODEL_API_KEY=replace-with-your-actual-keyEOFsudo chown workspace:workspace /srv/workspace/.envsudo chmod 600 /srv/workspace/.envsudo -u workspace test -r /srv/workspace/.env && echo "readable"
APP_HOST=127.0.0.1 means the service accepts connections only from the local machine, so external requests must go through Nginx. APP_PORT must match the port in the proxy_pass directive of the Nginx configuration later on.
Follow these rules for keys:
- Never write keys into code, screenshots, chat logs, or log files.
- Each member uses their own account and key. Do not share
MODEL_API_KEY. - If a key leaks, revoke the old key in the provider’s dashboard first. Then replace the value in
.envand restart the service.
5. Running as a Persistent systemd Service
Create the service file at /etc/systemd/system/workspace.service. Replace the node path in ExecStart with the output of command -v node from the previous step. Follow the project documentation for the entry file and startup arguments:
sudo tee /etc/systemd/system/workspace.service > /dev/null <<'EOF'[Unit]Description=Smart coding workspaceAfter=network-online.targetWants=network-online.target[Service]Type=simpleUser=workspaceGroup=workspaceWorkingDirectory=/srv/workspace/appEnvironmentFile=/srv/workspace/.envExecStart=/usr/bin/node /srv/workspace/app/server.jsRestart=on-failureRestartSec=5NoNewPrivileges=truePrivateTmp=trueProtectSystem=strictReadWritePaths=/srv/workspace/data /srv/workspace/logsProtectHome=trueUMask=0027[Install]WantedBy=multi-user.targetEOF
Here is what the key options do. Restart=on-failure restarts the process after a crash. NoNewPrivileges=true prevents the process from gaining privileges. ProtectSystem=strict makes system directories read-only, so the program can write only to data and logs. UMask=0027 keeps newly created files closed to other users by default.
Load and start the service, then verify it:
sudo systemd-analyze verify /etc/systemd/system/workspace.servicesudo systemctl daemon-reloadsudo systemctl enable --now workspacesystemctl status workspace --no-pagercurl -I http://127.0.0.1:8080
enable makes the service start automatically after the server reboots. If curl returns an HTTP status line, the program is listening on the local machine.
To roll back:
sudo systemctl disable --now workspacesudo rm /etc/systemd/system/workspace.servicesudo systemctl daemon-reload
6. Nginx Reverse Proxy and HTTPS
First, confirm that the domain already resolves to the server. The output of the following command should be the server’s public IP address:
dig +short workspace.example.com
Write the Nginx site configuration. The port in proxy_pass must match APP_PORT:
sudo tee /etc/nginx/sites-available/workspace > /dev/null <<'EOF'server {listen 80;server_name workspace.example.com;location / {proxy_pass http://127.0.0.1:8080;proxy_http_version 1.1;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;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";}}EOFsudo ln -s /etc/nginx/sites-available/workspace /etc/nginx/sites-enabled/sudo nginx -tsudo systemctl reload nginx
The Upgrade and Connection headers enable WebSocket support. Real-time features in programming workspaces typically depend on them.
Request a free certificate with certbot, and redirect HTTP to HTTPS automatically:
sudo apt install -y certbot python3-certbot-nginxsudo certbot --nginx -d workspace.example.com --redirectsudo certbot renew --dry-run
--dry-run only simulates renewal and does not change the existing certificate. If it passes, the certificate renews automatically on schedule.
7. Firewall and SSH Hardening
The firewall allows only ports 22, 80, and 443. Port 8080 listens only on the local machine and is not exposed to the internet.
Allow SSH before you enable the firewall. Otherwise, you may lock yourself out of the server:
sudo ufw allow 22/tcpsudo ufw allow 'Nginx Full'sudo ufw default deny incomingsudo ufw default allow outgoingsudo ufw enablesudo ufw status verbose
The cloud provider’s security group rules must match these settings. It is best to allow access to port 22 only from the administrator’s fixed IP address, and to open ports 80 and 443 to the public.
Check whether port 8080 is bound only to the local machine:
sudo ss -lntp | grep -E ':(80|443|8080|22)\s'
Port 8080 should appear as 127.0.0.1:8080, not 0.0.0.0:8080.
Before you harden SSH, generate a key pair on your local computer and upload the public key:
ssh-keygen -t ed25519 -C "admin@laptop"ssh-copy-id -i ~/.ssh/id_ed25519.pub admin-username@SERVER_IP
After you log in successfully with the key from a new terminal, change the server configuration. Keep your current session open while you test the login:
sudo tee /etc/ssh/sshd_config.d/99-hardening.conf > /dev/null <<'EOF'PasswordAuthentication noKbdInteractiveAuthentication noPermitRootLogin noPubkeyAuthentication yesMaxAuthTries 3EOFsudo sshd -t && sudo systemctl reload ssh
sshd -t checks the configuration syntax. Reload the service only if the check passes. Then open a new terminal and test the login. If you cannot log in, use the session you kept open to delete 99-hardening.conf, then run sudo systemctl reload ssh again.
8. Encrypted Backups and Restore Drills
Backups are encrypted on the server. The decryption private key stays only on the administrator’s local computer. Generate the key pair on your local computer:
age-keygen -o workspace-age.key
The command outputs a public key that starts with age1. Add this public key to the backup script on the server. Store the private key file workspace-age.key in an offline location, such as a password manager or an encrypted USB drive. Never store the private key on the server.
Install age on the server and create the backup script:
sudo apt install -y agesudo tee /usr/local/sbin/workspace-backup.sh > /dev/null <<'EOF'#!/usr/bin/env bashset -euo pipefailAGE_RECIPIENT="age1-replace-with-your-public-key"BACKUP_DIR=/srv/workspace/backupSTAMP=$(date +%Y%m%d-%H%M%S)OUT="$BACKUP_DIR/workspace-data-$STAMP.tar.gz.age"tar -C /srv/workspace -czf - data .env | age -r "$AGE_RECIPIENT" -o "$OUT"sha256sum "$OUT" > "$OUT.sha256"# List backups older than 14 days. After confirming the output, change -print to -delete.find "$BACKUP_DIR" -name 'workspace-data-*.age' -mtime +14 -printEOFsudo chmod 750 /usr/local/sbin/workspace-backup.shsudo /usr/local/sbin/workspace-backup.sh
The backup includes .env, but the entire file is encrypted. Decrypting it requires the private key on your local computer.
To run a backup every day at 3:30 AM, open the crontab editor:
sudo crontab -e
Add this line in the editor:
30 3 * * * /usr/local/sbin/workspace-backup.sh >> /srv/workspace/logs/backup.log 2>&1
A backup is not complete until you verify it. Run a restore drill at least once a month, using these steps.
First, copy the latest backup to the administrator’s home directory, then download it to your local computer. Replace the file name with the actual name:
sudo cp /srv/workspace/backup/workspace-data-XXXX.tar.gz.age ~/sudo chown $USER ~/workspace-data-XXXX.tar.gz.age
On your local computer, run:
scp admin-username@SERVER_IP:~/workspace-data-XXXX.tar.gz.age ./ssh admin-username@SERVER_IP "rm ~/workspace-data-XXXX.tar.gz.age"sha256sum -c workspace-data-XXXX.tar.gz.age.sha256age -d -i workspace-age.key -o restore.tar.gz workspace-data-XXXX.tar.gz.agemkdir restore-test && tar -xzf restore.tar.gz -C restore-testls -R restore-test | head -n 30
The drill runs locally and does not change production data. After sha256sum passes, confirm that the extracted file structure is correct.
To restore to the server for real, stop the service first, keep the current data, and then extract:
sudo systemctl stop workspacesudo mv /srv/workspace/data /srv/workspace/data.before-restore# Decrypt and extract to a temporary directory, then move the contents into data after verification.sudo systemctl start workspace
After the service starts, confirm that the page opens and the data is complete. Delete data.before-restore only after you have confirmed the restore.
9. Common Troubleshooting
Troubleshoot by symptom. Run the commands in the order listed.
Service does not start:
systemctl status workspace --no-pagersudo journalctl -u workspace -n 100 --no-pager
If the log shows EACCES or Permission denied, check the ownership of .env and the data and logs directories. If it shows ENOENT, check that the node path in ExecStart and the entry file exist.
Port is not listening:
sudo ss -lntp | grep 8080curl -I http://127.0.0.1:8080
If there is no output, the program is not running. Check the service logs.
502 Bad Gateway:
sudo nginx -tsudo tail -n 50 /var/log/nginx/error.log
The most common causes are a port mismatch between proxy_pass and APP_PORT, or a backend service that has crashed.
Certificate request fails:
dig +short workspace.example.comsudo ufw status verbosesudo certbot certificatessudo tail -n 50 /var/log/letsencrypt/letsencrypt.log
Certificate failures usually mean the domain does not resolve to the current server, or port 80 is not open to the public. Check both, including the cloud provider’s security group.
Port is unreachable:
sudo ufw status verbosecurl -I https://workspace.example.com
First, confirm that both UFW and the cloud security group allow the traffic.
