Hatty AI
Book a CallSchedule Strategy Session
ServicesSolutionsMarketingAI VisibilityIndustriesResourcesAboutWork
← Back to Blog

DevOps

Connect GitHub to a VPS With WHM and cPanel Git Version Control

Published March 6, 2026 · Hatty AI · 14 min read

Connect GitHub to your VPS with WHM and cPanel. SSH keys, cPanel Git Version Control, deployment hooks, and GitHub Actions automation.

Why Connect GitHub to Your VPS?

If you're running a VPS with WHM and cPanel, you're likely hosting WordPress sites, PHP applications, or Node.js projects for clients. Manually uploading files via FTP is slow, error-prone, and impossible to roll back. By connecting GitHub to your VPS, you get:

  • Version control — every change is tracked. Roll back to any previous version in seconds.
  • Automated deployments — push to main and your server updates automatically. No FTP, no SSH-ing in to pull.
  • Team collaboration — multiple developers can work on the same project without overwriting each other's files.
  • CI/CD integration — run tests before deploying. If tests fail, the deploy is blocked.

This guide assumes you have a VPS with WHM/cPanel already provisioned. If you need help choosing a hosting provider, Hatty AI offers managed hosting solutions with WHM/cPanel pre-configured.

📋 Prerequisites

  • A VPS with WHM and cPanel (CentOS/AlmaLinux/CloudLinux)
  • Root or reseller access to WHM
  • A GitHub account (Free tier works — see our GitHub account types guide)
  • A domain pointed to your VPS
  • SSH access enabled for the cPanel account

Step 1: Enable SSH Access in WHM

By default, cPanel accounts may not have SSH (shell) access enabled. You need to turn this on in WHM first.

  1. Log into WHM at https://your-server-ip:2087.
  2. Search for "Manage Shell Access" in the WHM search bar.
  3. Find the cPanel account you want to enable SSH for.
  4. Change the shell from Disabled to Normal Shell (/bin/bash).
  5. Click "Save".

📍 WHM path: WHM → Account Functions → Manage Shell Access

⚠️ Security Note

Only enable SSH for accounts that need it. For production servers, consider using a dedicated deploy user with limited permissions rather than the main cPanel account.

Step 2: Generate SSH Keys on Your Server

SSH keys provide passwordless, secure authentication between your server and GitHub.

  1. SSH into your server: ssh cpaneluser@your-server-ip
  2. Generate a new SSH key pair:
ssh-keygen -t ed25519 -C "deploy@yourdomain.com"
# Press Enter to accept default path (~/.ssh/id_ed25519)
# Leave passphrase empty for automated deployments
  1. Display your public key:
cat ~/.ssh/id_ed25519.pub

Copy the entire output — you'll add this to GitHub in the next step.

Step 3: Add the SSH Key to GitHub

There are two places you can add SSH keys in GitHub, and the choice matters:

Key Type Where to Add Access Level Best For
Deploy KeyRepo → Settings → Deploy KeysSingle repo (read or read/write)Production servers pulling one repo
Account SSH KeyGitHub → Settings → SSH KeysAll repos you have access toDev machines, multi-repo servers

Adding a Deploy Key (Recommended for Production)

  1. Go to your repo on GitHub → Settings → Deploy keys.
  2. Click "Add deploy key".
  3. Title: VPS Production - yourdomain.com
  4. Paste the public key from Step 2.
  5. Check "Allow write access" only if the server needs to push (usually not needed).
  6. Click "Add key".

Test the connection from your server:

ssh -T git@github.com
# Expected: "Hi username! You've successfully authenticated..."

Step 4: Clone Your Repo to the Server

Navigate to the directory where your site files live and clone the repository:

# Navigate to your document root
cd /home/cpaneluser/public_html

# If the directory has existing files, back them up first
mv public_html public_html_backup

# Clone the repo
git clone git@github.com:your-org/your-repo.git public_html

# Set proper ownership
chown -R cpaneluser:cpaneluser /home/cpaneluser/public_html

💡 cPanel Document Root Tip

cPanel typically uses /home/username/public_html as the document root. If you're using an addon domain, the path is usually /home/username/addondomain.com. Check cPanel → Domains to confirm.

Step 5: Use cPanel Git Version Control (Alternative Method)

cPanel has a built-in Git Version Control feature that provides a GUI for managing repos. Here's how to use it:

  1. Log into cPanel at https://yourdomain.com:2083.
  2. Search for "Git Version Control" in the cPanel search bar.
  3. Click "Create".
  4. Toggle "Clone a Repository" on.
  5. Clone URL: git@github.com:your-org/your-repo.git
  6. Repository Path: /home/cpaneluser/public_html
  7. Repository Name: your project name.
  8. Click "Create".

📍 cPanel path: cPanel → Files → Git Version Control

Setting Up the .cpanel.yml Deploy File

cPanel uses a .cpanel.yml file in your repo root to define deployment tasks. When you pull or push to the cPanel-managed repo, these tasks run automatically:

# .cpanel.yml
---
deployment:
  tasks:
    - export DEPLOYPATH=/home/cpaneluser/public_html
    - /bin/cp -R * $DEPLOYPATH/
    - cd $DEPLOYPATH && npm ci --production 2>/dev/null || true
    - cd $DEPLOYPATH && npm run build 2>/dev/null || true

Step 6: Automate Deploys with GitHub Actions

The most powerful approach combines GitHub Actions (CI/CD) with SSH deployment to your VPS. When you push to main, GitHub Actions runs your tests, builds the project, and deploys it to your server — all automatically.

If you haven't set up GitHub Actions yet, read our GitHub Account Types & CI/CD Guide first — it covers workflow files, secrets, and branch protection in detail.

The Deployment Workflow

# .github/workflows/deploy-to-vps.yml
name: Deploy to VPS

on:
  push:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
      - run: npm ci
      - run: npm test

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

      - name: Deploy via SSH
        uses: appleboy/ssh-action@v1
        with:
          host: ${{ secrets.VPS_HOST }}
          username: ${{ secrets.VPS_USER }}
          key: ${{ secrets.VPS_SSH_KEY }}
          port: ${{ secrets.VPS_PORT }}
          script: |
            cd /home/cpaneluser/public_html
            git fetch origin main
            git reset --hard origin/main
            npm ci --production
            npm run build

      - name: Verify Deployment
        uses: appleboy/ssh-action@v1
        with:
          host: ${{ secrets.VPS_HOST }}
          username: ${{ secrets.VPS_USER }}
          key: ${{ secrets.VPS_SSH_KEY }}
          port: ${{ secrets.VPS_PORT }}
          script: |
            curl -s -o /dev/null -w "%{http_code}" https://yourdomain.com | grep -q "200"

GitHub Secrets You Need

Secret Name Value Example
VPS_HOSTServer IP or hostname203.0.113.50
VPS_USERSSH usernamecpaneluser
VPS_SSH_KEYPrivate key content-----BEGIN OPENSSH PRIVATE KEY-----...
VPS_PORTSSH port (default 22)22

Step 7: Set Up Webhooks for Instant Deploys

An alternative to GitHub Actions is using GitHub Webhooks to trigger a deploy script on your server whenever code is pushed:

  1. Create a deploy script on your server:
#!/bin/bash
# /home/cpaneluser/deploy.sh
cd /home/cpaneluser/public_html
git fetch origin main
git reset --hard origin/main
npm ci --production 2>/dev/null
npm run build 2>/dev/null
echo "Deploy completed at $(date)" >> /home/cpaneluser/deploy.log
  1. Create a simple PHP webhook receiver:
<?php
// /home/cpaneluser/public_html/webhook.php
$secret = getenv('WEBHOOK_SECRET');
$signature = $_SERVER['HTTP_X_HUB_SIGNATURE_256'] ?? '';
$payload = file_get_contents('php://input');

if (hash_equals('sha256=' . hash_hmac('sha256', $payload, $secret), $signature)) {
    exec('/home/cpaneluser/deploy.sh > /dev/null 2>&1 &');
    http_response_code(200);
    echo 'Deploy triggered';
} else {
    http_response_code(403);
    echo 'Invalid signature';
}
?>
  1. In GitHub: repo → Settings → Webhooks → Add webhook.
  2. Payload URL: https://yourdomain.com/webhook.php
  3. Content type: application/json
  4. Secret: a secure random string (add to your server as an environment variable).
  5. Events: select "Just the push event".

Troubleshooting Common Issues

❌ "Permission denied (publickey)" when cloning

Cause: SSH key not recognized by GitHub.

Fix: Verify the key is added correctly with ssh -vT git@github.com. Check that ~/.ssh/config isn't overriding the identity file.

❌ "fatal: not a git repository" in cPanel Git

Cause: The directory already has files that aren't Git-tracked.

Fix: Back up existing files, remove the directory contents, then clone fresh. Or initialize Git in the existing directory with git init && git remote add origin ....

❌ File permissions wrong after git pull

Cause: Git doesn't preserve Unix ownership.

Fix: Add chown -R cpaneluser:cpaneluser /home/cpaneluser/public_html to your deploy script, and set chmod 755 for directories, chmod 644 for files.

❌ GitHub Actions deploy hangs

Cause: SSH connection blocked by firewall or CSF.

Fix: Whitelist GitHub Actions IP ranges in your server firewall. See GitHub's IP ranges. Or use a self-hosted runner inside your network.

Security Checklist for GitHub + VPS Deployments

  • ✅ Use deploy keys (repo-scoped) instead of account-wide SSH keys on production servers.
  • ✅ Store all credentials in GitHub Secrets, never in code.
  • ✅ Use a dedicated deploy user with minimal permissions — not root.
  • ✅ Enable 2FA on your GitHub account and all WHM/cPanel accounts.
  • ✅ Restrict SSH access to specific IP addresses via CSF or WHM Host Access Control.
  • ✅ Rotate SSH keys at least annually.
  • ✅ Keep .git directory outside your public document root, or block access via .htaccess.
  • ✅ Use webhook secrets with HMAC signature verification.

🔐 Critical: Protect Your .git Directory

If your .git folder is inside public_html, anyone can access your entire Git history. Add this to your .htaccess:

RedirectMatch 404 /\.git

Need a Managed VPS with GitHub Integration?

Hatty AI provides fully managed VPS hosting with pre-configured CI/CD pipelines, WHM/cPanel, and 24/7 monitoring for businesses across San Antonio and Texas.

Explore Hosting Solutions

Related: GitHub Account Types & CI/CD Guide · Managed IT Services · Essential Cybersecurity Practices

Frequently asked questions

Why connect GitHub to a VPS?

You get version control with easy rollbacks, automated deployments on push, team collaboration without overwriting files, and CI/CD integration to block failing deploys.

What are the steps to connect GitHub to a WHM/cPanel VPS?

Enable SSH access in WHM, generate SSH keys on the server, add the SSH key to GitHub, and clone your repository to the server.

Is there an alternative to cloning over SSH?

Yes. The guide's fifth step uses cPanel's Git Version Control feature as an alternative method.

Free review

Get a free review from an engineer

Tell us where your team loses the most time. Our engineers review your current setup and send back a prioritized plan for automation, software and security.

  • Reviewed by an engineer, not a bot
  • Prioritized by time saved and risk reduced
  • No obligation and no pressure

Prefer to talk? Call (210) 227-3444 or book a strategy session.

By submitting, you agree Hatty AI may contact you about your request. We never sell your information.

Talk with Hatty AI

Turn the problem into a clear technology and growth plan.

Tell us what you are trying to improve. We can help with AI automation, business intelligence, software, websites, managed IT, cybersecurity, compliance, and marketing growth.

Book a strategy session
Open the scheduling form on this page