How to Connect a Private GitHub Repo to cPanel (Step-by-Step)

GitHub ↔ cPanel” and the subtitle “SSH Keys • Deploy Keys • Clean Setup,” plus a GitHub icon and “Step-by-Step

Deploying from GitHub to cPanel can feel tricky at first, especially with SSH keys and private repositories. This guide walks through a clean setup from scratch.

Why use this method?

  • Easy to update after each push
  • Works with private GitHub repos
  • More secure than manual uploads

Prerequisites

  • A cPanel account with Terminal/SSH access
  • A GitHub repository
  • Domain already pointed to your hosting account

1. Generate an SSH key on your cPanel server

In cPanel Terminal:

ssh-keygen -t ed25519 -C "cpanel-deploy" -f ~/.ssh/id_ed25519 -N ""
cat ~/.ssh/id_ed25519.pub

Copy the public key output.

2. Add the key to GitHub

In your GitHub repo:

  • Go to Settings → Deploy keys
  • Click Add deploy key
  • Paste the public key
  • Keep write access off unless you specifically need push from server

This allows your server to read your private repo securely.

3. Configure SSH on cPanel

Create/update ~/.ssh/config:

Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519
  IdentitiesOnly yes

Then run:

chmod 600 ~/.ssh/config
ssh -T git@github.com

4. Clone the repository using SSH

Use SSH URL (not HTTPS):

cd ~
git clone git@github.com:YOUR_USERNAME/YOUR_REPO.git repositories/your-repo

5. Deploy files to your website folder

Copy repo files to your domain’s document root (example: public_html):

rsync -av --delete ~/repositories/your-repo/ ~/public_html/

Now your site files are live.

6. Updating after future GitHub pushes

When you push new changes:

cd ~/repositories/your-repo
git pull origin main
rsync -av --delete ./ ~/public_html/

Common errors and fixes

  • could not read Username for ‘https://github.com’
    You used HTTPS. Switch remote to SSH.
  • Permission denied (publickey)
    Wrong/missing deploy key, or SSH config not using correct key.
  • Wrong branch (main vs master)
    Pull the branch that actually exists.

This setup gives you a secure and repeatable GitHub-to-cPanel deployment flow without making your repository public.

Leave a Reply

Your email address will not be published. Required fields are marked *