Updated November 30, 2026
Manually deploying updates to your website or application quickly becomes tiresome. Manually connecting to your server via a terminal session, pulling the latest version of your code from the remote repository, installing the necessary packages, and restarting your application works perfectly well when you update your site once per month. When your team starts deploying multiple changes per day, manual deployments become slow, repetitive, and error-prone. Automated VPS deployment using GitHub Actions and Secure Shell (SSH) simplifies this process.
Each time you push or merge approved code into the main branch, GitHub can automatically deploy updates and restart the application on the virtual server. This step-by-step guide explains how to set up automated deployments for a virtual private server (VPS) without a complex DevOps toolset.
Prerequisites for Automated VPS Deployment
Before automating deployments, you need a Linux virtual private server that is up and running, with SSH access, a GitHub repository that hosts your project code, and a pair of SSH keys.
Make sure three simple prerequisites are ready before creating your workflow file:
- A Cloud VPS With Root or Sudo Access:Your application should already be set up and running on a Linux server (such as Ubuntu or Debian). Teams serving users across South Asia can host their applications on a VPS server in India through providers like CloudPe, which offers Tier-4 data centers in Mumbai, Delhi NCR, and Chennai with NVMe storage, local rupee billing, and zero outbound data egress fees.
- Your Project Cloned on the Server: Clone your GitHub project to your VPS only once (say, into /var/www/my-app) and make sure your application is running properly.
- A Process Manager for Your App:Install a process manager such as PM2 for Node.js projects or Systemd, Gunicorn for Python applications, or even Docker Compose, so that your deployment script can easily restart your application with just one command.
How to Configure SSH Keys and GitHub Secrets Safely?
You configure SSH keys and GitHub Secrets safely by generating a dedicated key pair on your server, adding the public key to your authorized keys file, and storing the private key inside encrypted GitHub repository secrets.
Never type your server password or paste a raw private key directly into your workflow file, because anyone with read access to your code could see it. Instead, follow these three steps:
- Generate a dedicated SSH key pair:Log into your VPS and create a separate SSH key used only for GitHub deployments:ssh-keygen -t ed25519 -f ~/.ssh/github_deploy -C “github-actions.” Press Enter when asked for a passphrase so GitHub Actions can log in automatically without human input.
- Authorize the public key on your VPS:Add the newly created public key to your server’s list of trusted keys: cat ~/.ssh/github_deploy.pub >> ~/.ssh/authorized_keyschmod 600 ~/.ssh/authorized_keys
- Add your credentials to GitHub Secrets:Open your repository on GitHub, go to Settings, select Secrets and variables, click Actions, and create four repository secrets:
- VPS_HOST: Your server’s public IP address.
- VPS_USERNAME: Your Linux login user (such as deployor ubuntu).
- VPS_PORT: Your SSH port (usually 22).
- VPS_SSH_KEY: The entire contents of your private key file (cat ~/.ssh/github_deploy), including the BEGINand END
How to Write the GitHub Actions Deployment Workflow File?
You write the GitHub Actions deployment workflow by creating a YAML file inside your repository’s .github/workflows folder that listens for pushes to your main branch and executes your server update commands over SSH.
Inside your local project folder, create a file named .github/workflows/deploy.yml and add the following configuration:
name: Deploy to VPS
on:
push:
branches:
- main
permissions:
contents: read
concurrency:
group: production-deployment
cancel-in-progress: false
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Connect via SSH and Deploy
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USERNAME }}
key: ${{ secrets.VPS_SSH_KEY }}
port: ${{ secrets.VPS_PORT }}
fingerprint: ${{ secrets.VPS_FINGERPRINT }}
script: |
set -e
cd /var/www/my-app
git pull --ff-only origin main
npm ci --omit=dev
pm2 restart my-app
Here is how this short file keeps your deployments predictable:
- Branch trigger (on: push):The workflow runs automatically only when code is pushed or merged into main, leaving experimental feature branches untouched.
- Secure SSH action (appleboy/ssh-action@v1):This popular open-source action reads your encrypted GitHub Secrets and opens an SSH session to your server.
- Fail-safe execution (set -e):Adding set -e at the top of your script tells the server to stop immediately if any command fails, preventing broken code from restarting your live site.
Commit and push this YAML file to GitHub, then open the Actions tab in your repository to watch your first automated deployment run in real time.
What Best Practices Keep Automated VPS Deployments Reliable and Secure?
The best practices that keep automated VPS deployments reliable and secure include using a non-root deploy user, isolating internal services on private networks, testing changes in staging first, and keeping automated server snapshots ready.
Once your basic pipeline is running, four simple habits will protect your production server as your team grows:
- Deploy with a limited Linux user: Create a dedicated deploy user that owns only your website folder and can restart your app, rather than logging in as root for routine updates.
- Isolate databases on a private network: If your web server talks to a separate database instance, place both servers inside a virtual private cloud (VPC) so internal traffic travels over private IP addresses instead of the public internet.
- Use a staging branch for risky updates: Point a staging branch to a smaller test VPS so your team can verify new features in a live browser before merging into main.
- Keep automated snapshots enabled: Turn on scheduled VPS snapshots in your cloud dashboard so you can roll back your entire server in minutes if a major software upgrade ever misbehaves.
Frequently Asked Questions (FAQs)
Q1. Is it safe to use GitHub Actions and SSH to deploy to a live production VPS?
Answer: Yes, it is safe to use GitHub Actions and SSH for production deployment, since your private key remains encrypted in GitHub Secrets, all terminal commands are sent over an encrypted SSH connection, and you can limit the permissions of the deploy user.
Q2. Do you need Docker or Kubernetes to automate deployments on a VPS?
Answer: No, you do not need Docker or Kubernetes to automate deployments on a VPS because a simple GitHub Actions SSH workflow can run standard git pull, package installation, and service restart commands directly on a lightweight Linux server.
Q3. Can you deploy a private GitHub repository onto your VPS automatically?
Answer: Certainly. You can automatically push a private GitHub repository to your VPS via a read-only GitHub Deployment Key, which will allow the server to pull from your private repository without prompting you for a password.
Recommended Articles
We hope this comprehensive guide to automated VPS deployment helps you streamline application updates and build secure deployment workflows. Check out these recommended articles for more insights and strategies to enhance server management, cloud infrastructure security, and DevOps automation.
