NEWUse coupon code SMX20 to get 20% OFF your first billing cycle on any game server or VPS!Explore Store

VPS HOSTING

How to Deploy Applications Automatically Using GitHub Actions and a VPS

Set up continuous deployment from GitHub Actions to a VPS: a restricted deploy user and SSH key, repository secrets, a workflow that tests then deploys, release directories with health checks, and safe rollbacks.

Manual deploys are slow and easy to get wrong: a forgotten migration, a missed file, a server left half-updated. With GitHub Actions, every push to your main branch can be tested and deployed the same way, with a log of exactly what happened. This guide uses plain SSH and a small deploy script, which works for almost any stack and keeps you in control.

How It Fits Together

push to main ─▶ GitHub Actions runner
                 1. checkout, install, test
                 2. build release (archive or image)
                 3. scp release ─▶ VPS:/srv/app/releases/<sha>
                 4. ssh deploy@VPS "/srv/app/deploy.sh <sha>"
                        └─ migrate, switch symlink, restart, health check

Step 1: A Restricted Deploy User

sudo adduser --disabled-password deploy
sudo mkdir -p /srv/app/releases
sudo chown -R deploy:deploy /srv/app

# on your computer: a key used only for deployments
ssh-keygen -t ed25519 -f deploy_key -C "github-actions" -N ""
# add deploy_key.pub to /home/deploy/.ssh/authorized_keys on the VPS

Give this user only what deploys need. If the deploy must restart a service, allow exactly that command with sudo:

# /etc/sudoers.d/deploy  (edit with: sudo visudo -f /etc/sudoers.d/deploy)
deploy ALL=(root) NOPASSWD: /usr/bin/systemctl restart app

Never reuse your personal SSH key in CI. A dedicated key can be revoked without affecting anything else (see our SSH key guide).

Step 2: Repository Secrets

In the repository, go to Settings → Secrets and variables → Actions and add:

  • DEPLOY_HOST: the server's IP or hostname
  • DEPLOY_KEY: the contents of deploy_key (the private key)
  • DEPLOY_KNOWN_HOSTS: the output of ssh-keyscan -t ed25519 YOUR_SERVER, checked against the server's real fingerprint

Pinning the host key prevents the workflow from connecting to an impostor server. Disabling host key checking is a common shortcut that removes this protection.

Step 3: The Deploy Script on the Server

#!/usr/bin/env bash
# /srv/app/deploy.sh <release-id>
set -euo pipefail
REL=/srv/app/releases/$1
cd "$REL"
ln -sfn /srv/app/shared/.env .env
# app-specific steps, e.g.:
# ./bin/migrate
ln -sfn "$REL" /srv/app/current.new && mv -T /srv/app/current.new /srv/app/current
sudo /usr/bin/systemctl restart app
for i in $(seq 1 20); do
  curl -fsS http://127.0.0.1:8000/health >/dev/null && { echo "healthy"; exit 0; }
  sleep 2
done
echo "health check failed" >&2
exit 1

The symlink switch with mv -T is atomic, so the application never sees a half-copied release. Keep the last few releases for rollback; our zero-downtime deployment guide explains the pattern and how to avoid dropping requests during restarts.

Step 4: The Workflow

# .github/workflows/deploy.yml
name: Test and deploy
on:
  push:
    branches: [main]

concurrency:
  group: deploy-production
  cancel-in-progress: false

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: production
    steps:
      - uses: actions/checkout@v4

      - name: Install and test
        run: |
          npm ci
          npm test
          npm run build

      - name: Package release
        run: tar -czf release.tgz dist package.json package-lock.json

      - name: Configure SSH
        run: |
          install -m 700 -d ~/.ssh
          echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_ed25519
          chmod 600 ~/.ssh/id_ed25519
          echo "${{ secrets.DEPLOY_KNOWN_HOSTS }}" > ~/.ssh/known_hosts

      - name: Upload and deploy
        env:
          HOST: ${{ secrets.DEPLOY_HOST }}
          SHA: ${{ github.sha }}
        run: |
          ssh deploy@"$HOST" "mkdir -p /srv/app/releases/$SHA"
          scp release.tgz deploy@"$HOST":/srv/app/releases/$SHA/
          ssh deploy@"$HOST" "cd /srv/app/releases/$SHA && tar -xzf release.tgz && rm release.tgz && npm ci --omit=dev && /srv/app/deploy.sh $SHA"

Adapt the build and install commands to your stack. concurrency ensures two deploys never run at the same time. Using the commit SHA as the release name makes it obvious which version is live.

Step 5: Approvals and Environments

Under Settings → Environments, create production and add required reviewers. The workflow then pauses before the deploy job until someone approves it. Environment-level secrets keep production credentials separate from staging; a second workflow (or job) can deploy every push to staging automatically (see our staging guide).

Variant: Deploying Docker Images

For containerised apps, build and push an image to a registry in the workflow, then on the server run docker compose pull and docker compose up -d with the new image tag. Tag images with the commit SHA rather than only latest, so you can roll back to a known version (see our Docker guide).

Rolling Back

# on the server: point current at the previous release
ls -1t /srv/app/releases | head
/srv/app/deploy.sh <previous-sha>

Or re-run the workflow for an earlier commit. Database migrations must be backward compatible for rollbacks to be safe.

Security Checklist

  • A dedicated deploy user and key, with sudo limited to specific commands.
  • Pinned host keys in known_hosts.
  • Secrets only in GitHub Secrets or environment secrets, never in the workflow file or logs.
  • Pin third-party actions to a version or commit SHA, and keep their use to a minimum.
  • Do not run deploy workflows on pull requests from forks.

ServoMix Plans for This Workload

Deploying from GitHub's hosted runners adds no load to your server beyond the deploy itself. If you build on the server or run a self-hosted runner there, choose at least 4 vCores / 16 GB so builds do not slow the live application.

AMD EPYC 7C13 VPS

Dedicated KVM vCores on AMD EPYC 7C13 (up to 3.70 GHz) with DDR4 ECC memory, NVMe SSD and an unmetered 1 Gbps port.

PlanvCoresRAMStorageNetworkPriceGood forBuy
SMX vPro XS (AMD EPYC)28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹420/moWebsites, small APIs, bots, staging and VPN serversOrder
SMX vPro S (AMD EPYC)416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹560/moWooCommerce, Node.js/Python backends, Docker Compose stacks, CI runnersOrder
SMX vPro M (AMD EPYC)832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹840/moProduction databases, high-traffic sites, multi-container appsOrder
SMX vPro L (AMD EPYC)1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹1,120/moLarge production workloads, SaaS platforms, analytics, in-memory cachesOrder

Intel Xeon Platinum 8269CY VPS

KVM VPS on Intel Xeon Platinum 8269CY (up to 3.80 GHz Turbo) with DDR4 ECC memory, NVMe SSD, full root access and an unmetered 1 Gbps port.

PlanvCoresRAMStorageNetworkPriceGood forBuy
SMX vCore XS (Intel Xeon)28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹270/moBusiness websites, small apps, scheduled jobs and botsOrder
SMX vCore S (Intel Xeon)416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹1,169/monthBusiness software, mid-size databases, several sites on one serverCheck stock
SMX vCore M (Intel Xeon)832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹2,249/monthERP/CRM stacks, heavier databases, multiple production appsCheck stock
SMX vCore L (Intel Xeon)1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹4,248/monthHigh-memory workloads and consolidated production serversCheck stock

Prices are monthly in INR as listed on the ServoMix store (verified 2026-11-14). Stock and final pricing are shown on the product page at checkout.

Frequently Asked Questions

Can GitHub Actions deploy to my own VPS?
Yes. A workflow connects over SSH with a dedicated deploy key stored in repository secrets, copies the release and runs a deploy script on the server.
Is it safe to store an SSH key in GitHub Secrets?
Yes, if the key is used only for deployments, belongs to a restricted user and can be revoked. Secrets are encrypted and masked in logs.
Should I disable host key checking in the workflow?
No. Store the server's host key in a secret and write it to known_hosts so the workflow only connects to your real server.
How do I require approval before production deploys?
Create a production environment with required reviewers and reference it in the deploy job; the workflow waits for approval.
How do I roll back a bad deploy?
Switch the current symlink to the previous release with the deploy script, or re-run the workflow on an earlier commit. Keep migrations backward compatible.
Should I build on GitHub's runners or on the VPS?
Building on GitHub's runners keeps load off your server. Build on the server or a self-hosted runner only if you need special hardware or private network access.
How do I prevent two deploys running at once?
Add a concurrency group to the workflow so deploys queue instead of overlapping.
Can I deploy Docker containers this way?
Yes. Build and push an image in the workflow, then pull and restart it on the server with Docker Compose, tagging images with the commit SHA.
What does the deploy user need permission to do?
Write to the application directory and restart the service. Limit sudo to the exact commands required.
Which ServoMix plan suits CI/CD deployments?
Any AMD EPYC or Intel VPS receives deployments. If you also run builds or a self-hosted runner on the server, choose 4 vCores / 16 GB or more.

Frequently Asked Questions

Can GitHub Actions deploy to my own VPS?

Yes. A workflow connects over SSH with a dedicated deploy key stored in repository secrets, copies the release and runs a deploy script on the server.

Is it safe to store an SSH key in GitHub Secrets?

Yes, if the key is used only for deployments, belongs to a restricted user and can be revoked. Secrets are encrypted and masked in logs.

Should I disable host key checking in the workflow?

No. Store the server's host key in a secret and write it to known_hosts so the workflow only connects to your real server.

How do I require approval before production deploys?

Create a production environment with required reviewers and reference it in the deploy job; the workflow waits for approval.

How do I roll back a bad deploy?

Switch the current symlink to the previous release with the deploy script, or re-run the workflow on an earlier commit. Keep migrations backward compatible.

Should I build on GitHub's runners or on the VPS?

Building on GitHub's runners keeps load off your server. Build on the server or a self-hosted runner only if you need special hardware or private network access.

How do I prevent two deploys running at once?

Add a concurrency group to the workflow so deploys queue instead of overlapping.

Can I deploy Docker containers this way?

Yes. Build and push an image in the workflow, then pull and restart it on the server with Docker Compose, tagging images with the commit SHA.

What does the deploy user need permission to do?

Write to the application directory and restart the service. Limit sudo to the exact commands required.

Which ServoMix plan suits CI/CD deployments?

Any AMD EPYC or Intel VPS receives deployments. If you also run builds or a self-hosted runner on the server, choose 4 vCores / 16 GB or more.

Was this article helpful?

Your feedback helps us continuously improve ServoMix guides.

Share this article

Know someone who may find this guide useful?

Deploy to a VPS Automatically with GitHub Actions | ServoMix