Blog

How to Deploy a GitHub Project to cPanel Using SSH

How to Deploy a GitHub Project to cPanel Using SSH

Deploying a project manually to cPanel every time you make a change can quickly become repetitive. Instead of repeatedly uploading ZIP files or replacing files through File Manager, you can connect your cPanel server directly to GitHub using Git and SSH.

In this guide, we’ll configure SSH authentication between your cPanel account and GitHub, clone your project onto the server, and use git pull whenever you want to deploy the latest changes.

1. Access the cPanel Terminal

Log in to your cPanel account and open Terminal.

If your hosting provider does not provide the Terminal feature, you may need to connect to the server using SSH from your computer instead.

Once connected, confirm that Git is available:

git --version

You should see the installed Git version.

2. Generate an SSH Key

Generate a new SSH key that cPanel will use to authenticate with GitHub:

ssh-keygen -t ed25519 -C "your-email@example.com"

Press Enter to accept the default location:

~/.ssh/id_ed25519

This creates two files:

id_ed25519
id_ed25519.pub

The first file is your private key. Keep it secret and never upload or share it.

The .pub file is your public key, which can safely be added to GitHub.

3. Copy Your Public SSH Key

Display the public key by running:

cat ~/.ssh/id_ed25519.pub

The output should look similar to:

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA... your-email@example.com

Copy the entire line.

4. Add the SSH Key to GitHub

Log in to GitHub and navigate to:

Settings → SSH and GPG keys → New SSH key

Give the key a descriptive name such as:

cPanel Server

Paste the public key you copied from cPanel and save it.

GitHub can now recognize authentication requests made using the corresponding private key on your cPanel server.

5. Test the GitHub Connection

Return to the cPanel Terminal and run:

ssh -T git@github.com

The first time you connect, SSH may ask whether you trust GitHub's host.

After successful authentication, GitHub should return a message indicating that authentication succeeded but shell access is not provided.

This is normal. GitHub uses the SSH connection for Git operations rather than giving you an interactive server shell.

6. Clone Your Project

Navigate to the directory where you want your project deployed.

For example:

`cd ~/public_html`

Clone your repository using its SSH URL:

git clone git@github.com:username/project.git

7. Deploy Future Updates with Git Pull

Once the project has been cloned, you don't need to clone it again whenever you make changes.

Your normal workflow becomes:

Local Computer
      ↓
git push
      ↓
GitHub
      ↓
git pull
      ↓
cPanel Server

After pushing changes from your development machine to GitHub, connect to your cPanel Terminal, navigate to the project and run:

git pull

For example:

cd ~/public_html/project
git pull

Git downloads the latest commits from GitHub and updates the files on your server.

Typical Deployment Workflow

During normal development, you might make changes locally and run:

git add .
git commit -m "Update project"
git push

Then on your cPanel server:

cd ~/public_html/project
git pull

Your latest committed code is now on the server.

Important Security Note

Never copy your private SSH key to GitHub or include it inside your repository.

Only this file should be copied to GitHub:

~/.ssh/id_ed25519.pub

Never share:

~/.ssh/id_ed25519

It is also a good practice to ensure sensitive project files such as .env are excluded from Git using .gitignore.

Check the Last Commit on cPanel

If you want to confirm that the latest changes on your cPanel server correspond to the latest commit you pushed to GitHub, you can check the most recent commit message.

Inside your project directory, run:

git log -1 --pretty=%B

This displays the commit message for the latest commit currently checked out on the cPanel server.

For example, if your latest GitHub commit was:

Fix checkout validation and update dashboard

and the cPanel command displays the same message, that is a useful quick indication that you're looking at the expected commit.

For a more reliable comparison, you can also check the commit hash:

git rev-parse HEAD

You can compare this hash with the latest commit hash shown on GitHub. If the hashes match, the cPanel working copy is pointing to that same commit.

You can also run:

git status

This helps identify local modifications on the server that have not been committed and could make the deployed files differ from the repository.

Conclusion

Using GitHub and SSH makes deploying projects to cPanel much easier than manually uploading files after every update.

Once the initial SSH connection is configured, your deployment process can be as simple as:

git pull

This gives you a straightforward workflow:

Write Code → Commit → Push to GitHub → Pull on cPanel → Verify Commit → Deploy

For larger applications, you can extend this approach with deployment scripts or CI/CD so that additional deployment tasks such as installing dependencies, building production assets, running migrations, or clearing application caches can be handled consistently as part of each release.

Scroll