DEV Community

igbojionu
igbojionu

Posted on

How I Fixed “Permission Denied (publickey)” While Connecting cPanel to GitHub (Complete Guide for Django Developers)

INTRODUCTION

If you’ve ever tried connecting your cPanel server to GitHub and saw this frustrating error:

Permission denied (publickey)

you are not alone.

I recently went through this exact issue while trying to deploy a Django application from GitHub to a cPanel server. I followed all the “correct” steps, generated my SSH key, added it to GitHub, and still… it didn’t work.

But here’s the interesting part:

The problem was not what I initially thought.

And that’s why I’m writing this — so you don’t waste hours chasing the wrong issue.

In this guide, I’ll walk you through:

  • what passwordless SSH actually is
  • why Django developers should care
  • the correct way to set it up on cPanel
  • the hidden mistakes that break everything
  • how to properly debug SSH issues
  • and how this ties into GitHub CI/CD

WHAT IS PASSWORDLESS SSH (IN SIMPLE TERMS)

When your server connects to GitHub, it needs to prove its identity.

There are two ways:

  1. Username + password (not recommended)
  2. SSH keys (recommended)

SSH keys work like this:

  • Your server keeps a private key
  • GitHub stores the public key
  • When connecting, GitHub verifies the match

If they match → access granted
If not → Permission denied

So “passwordless SSH” simply means authentication happens automatically using keys instead of typing passwords.


WHY THIS MATTERS (ESPECIALLY FOR DJANGO DEVELOPERS)

If you are building real-world Django apps — client systems, portals, dashboards — this setup is extremely important.

It allows you to:

  • deploy faster (git pull without login prompts)
  • keep credentials secure
  • prepare for CI/CD pipelines
  • avoid manual file uploads
  • maintain a professional workflow

Think about it:

You push code → your server pulls it → your app updates

That’s the beginning of proper DevOps.


THE REAL PROBLEM MOST PEOPLE FACE

Let me save you time.

Most people think the error:

Permission denied (publickey)

means:

“My SSH key is wrong”

But in many cases, that is NOT the issue.

The real causes are usually:

  • wrong SSH username (very common)
  • wrong repository URL
  • SSH not using the correct key
  • missing SSH config
  • wrong file permissions

I personally hit almost all of these.


STEP-BY-STEP SETUP (THE RIGHT WAY)


STEP 1: OPEN TERMINAL IN CPANEL

Go to:

cPanel → Advanced → Terminal

Then run:

cd ~/.ssh

If it doesn’t exist:

`mkdir -p ~/.ssh
chmod 700 ~/.ssh
cd ~/.ssh

`

STEP 2: GENERATE SSH KEY

Run:

ssh-keygen -t rsa -b 4096 -C "{[your_email@example.com](mailto:your_email@example.com)}"

OR:

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

Now you’ll see:

Enter file in which to save the key:

You have two choices:

Option A (Recommended):
Press Enter → uses default id_rsa

Option B (Advanced):
Type a custom name like:

portal

This creates:

~/.ssh/portal
~/.ssh/portal.pub

Then:

Enter passphrase → press Enter twice


STEP 3: VERIFY KEY FILES

Run:

ls -la ~/.ssh

You should see:

id_rsa
id_rsa.pub

OR:

portal
portal.pub


STEP 4: COPY PUBLIC KEY

Run:

cat ~/.ssh/id_rsa.pub

OR:

cat ~/.ssh/{your_key_name}.pub

Copy everything.


STEP 5: ADD TO GITHUB

Go to:

{your_github_repo_url}

Navigate to:

Settings → Deploy Keys → Add deploy key

Paste your key.

Important:

Deploy keys are repo-specific
So make sure you add it to the exact repository you want to use.


STEP 6: TEST CONNECTION

Run:

ssh -T git@github.com

If successful:

Hi {your_github_username}! You've successfully authenticated...

If not → don’t panic yet.


WHERE EVERYTHING CAN GO WRONG (REAL LESSONS)


PROBLEM 1: CUSTOM KEY NAME (VERY COMMON)

If you saved your key as:

portal

Then SSH does NOT automatically use it.

So this fails:

ssh -T git@github.com

But this works:

ssh -i ~/.ssh/portal -T git@github.com

This means:

Your key is correct
But SSH is not using it automatically


FIX: CREATE SSH CONFIG

Run:

cat > ~/.ssh/config <<EOF
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/{your_key_name}
IdentitiesOnly yes
EOF

Then:

chmod 600 ~/.ssh/config

Now test again:

ssh -T git@github.com


PROBLEM 2: WRONG SSH USERNAME (BIGGEST MISTAKE)

Error example:

{your_cpanel_username}@github.com: Permission denied

This is wrong.

GitHub ONLY accepts:

git@github.com


CORRECT FORMAT

git@github.com:{your_github_username}/{your_repo}.git


WRONG FORMAT

{your_cpanel_username}@github.com:{your_repo}.git

This single mistake can waste hours.


PROBLEM 3: WORKS IN TERMINAL BUT FAILS IN CPANEL

This happened to me.

Why?

Because:

  • terminal used correct key manually
  • cPanel Git used default SSH behavior

Solution:

  • ensure SSH config is set
  • ensure repo URL is correct

PROBLEM 4: CONFIG FILE NOT CREATED

Error:

cannot access ~/.ssh/config

This simply means:

You opened nano but didn’t save

Fix:

Recreate config properly.


PROBLEM 5: FILE PERMISSIONS

SSH is very strict.

Run:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/config
chmod 600 ~/.ssh/{private_key}
chmod 644 ~/.ssh/{public_key}

If permissions are wrong → SSH ignores your key.


HOW TO DEBUG LIKE A PRO

Instead of guessing, use these:


  1. Check files

ls -la ~/.ssh


  1. Check config

cat ~/.ssh/config


  1. Test connection

ssh -T git@github.com


  1. Test specific key

ssh -i ~/.ssh/{your_key_name} -T git@github.com


  1. Use verbose mode

ssh -v -T git@github.com

Look for:

Offering public key
Authentication succeeded


  1. Test repo access

git ls-remote git@github.com:{your_github_username}/{your_repo}.git

If this works → everything is fine.


CONNECTING THROUGH CPANEL

Go to:

cPanel → Git Version Control → Create

Use:

git@github.com:{your_github_username}/{your_repo}.git

Choose your folder and create.


WHY THIS MATTERS FOR CI/CD

This setup is not just about fixing SSH.

It’s the foundation for:

  • automated deployments
  • GitHub Actions
  • safer releases
  • testing before deployment
  • scaling your Django projects

Imagine:

You push code → server updates automatically

That’s where this is going.


BEST PRACTICE (IMPORTANT)

If you are just starting:

Use default key name (id_rsa)

It avoids:

  • SSH config issues
  • key selection problems

Custom keys are powerful, but require more setup.


FINAL CHECKLIST

Before saying “it’s not working”, confirm:

  • SSH key exists
  • public key is on GitHub
  • correct repo URL is used
  • SSH config exists (if needed)
  • permissions are correct
  • ssh -T works
  • git ls-remote works

CONCLUSION

Setting up passwordless SSH between cPanel and GitHub is simple in theory, but small mistakes can break everything.

The biggest lessons:

  • GitHub uses git@github.com, not your server username
  • custom key names need SSH config
  • deploy keys are repo-specific
  • verbose SSH is your best debugging tool

Once you understand this, deployments become smoother and more reliable.

And more importantly — you are now one step closer to proper CI/CD.


If you’ve ever struggled with this error, you’re not alone.

The real difference is not avoiding the problem — it’s knowing how to debug it properly.

Top comments (0)