Forget FTP: How to Auto-Deploy from GitHub to VPS via Actions (CI/CD Guide)

Are you still dragging and dropping files using FileZilla every time you update your website? It’s time to stop. Not only is manual uploading slow, but it's also prone to errors. Imagine pushing a "Save" button on your laptop, and watching your live server update itself instantly. That is the power of CI/CD.

In this guide, I will show you how to set up GitHub Actions to automatically deploy your code to a VPS (AlmaLinux/Ubuntu) safely via SSH.

Stop using FileZilla. Learn how to automatically deploy your code from GitHub to your VPS using GitHub Actions. A complete CI/CD guide for beginners.

Why You Need This Workflow

  • Speed: No more waiting for FTP transfers.
  • Safety: If the code breaks, you can roll back instantly via Git.
  • Professionalism: This is how top-tier developers work in 2025.

Step 1: Generate SSH Keys

First, your GitHub repository needs permission to access your server without a password. Run this on your local PC or VPS terminal:

ssh-keygen -t rsa -b 4096 -C "github-actions"

This creates a private key and a public key.

  • Add the Public Key (.pub) to your VPS inside ~/.ssh/authorized_keys.
  • Copy the Private Key content; we will need it for GitHub.

Step 2: Configure GitHub Secrets

Go to your GitHub Repository > Settings > Secrets and variables > Actions.
Add these new repository secrets:

  • HOST: Your VPS IP Address.
  • USERNAME: Your VPS username (e.g., root or admin).
  • SSH_KEY: Paste the Private Key you copied earlier.

Step 3: Create the Workflow File

In your project folder, create this directory structure: .github/workflows/deploy.yml.
Paste this code:

name: Deploy to VPS
on:
  push:
    branches: [ main ]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Deploy via SSH
      uses: appleboy/ssh-action@master
      with:
        host: ${{ secrets.HOST }}
        username: ${{ secrets.USERNAME }}
        key: ${{ secrets.SSH_KEY }}
        script: |
          cd /var/www/html/my-website
          git pull origin main

Conclusion

Once you commit and push this file, GitHub Actions will trigger. Check the "Actions" tab in your repo to watch the magic happen. You have just built your first automated deployment pipeline!

Post a Comment for "Forget FTP: How to Auto-Deploy from GitHub to VPS via Actions (CI/CD Guide)"