Cantech Knowledge Base

Your Go-To Hosting Resource

Learn to Set Up Access to Private Repositories Using Git

To access a private Git repository, generate an SSH key pair (essh-keygen), add the public key to your repository host (e.g., GitHub → Settings → Deploy Keys), then clone using git clone [email protected]:username/repo.git. Alternatively, use a Personal Access Token over HTTPS if SSH isn’t available.

Introduction

When your code is stored in a private repository, it is protected for a reason. Only selected users should get access, and for that, Git needs proper authentication. Git works best with SSH when it comes to secure access. The process to set this up helps Git understand that it is you trying to fetch or push code, and not a hacker or intruder.

The steps are mostly the same for GitHub or another platform that hosts private repositories. So, though this article will take GitHub as our main example, if you are using something like GitLab, Bitbucket, or any other similar service, you can follow along with small changes.

Moreover, this process assumes that you have access to cPanel or a similar control panel (WHM v70) with shell access. For a more recent version of cPanel (version 72 or later), you will be able to utilise the Terminal feature to run commands directly from the cPanel interface. This makes it easier to generate keys and clone repositories without needing to leave the platform.

Let’s go step-by-step and see how to set this up properly.

Guide to Set Up SSH Access to Private Repositories

Create Your SSH Key

The first step is to create an SSH key pair on your local machine (or in the terminal of your cPanel). You will need to generate it in case you do not have one. With this key, you can establish a secure connection between your local system and the private repository host.

Open your terminal and enter the following command:

ssh-keygen -t rsa -b 4096 -C "username@example"

Here, replace [email protected] with your actual email address.

Note – You can leave the passphrase field empty by pressing Enter. However, without one, anyone with access to your private key file can use it.

The system will generate a public and private key pair, stored in the .ssh directory of your home folder.

Check if the SSH Key is Created Properly

Now, confirm that your SSH key is sitting in the right place.

Use this command:

cat ~/.ssh/id_rsa.pub

This should print out a long string starting with ssh-rsa and a bunch of characters after that. If you see something like that, your key is ready to go.

Note the full key; you will need to copy and paste this into your repository host to register it.

If the system tells you something like:

cat: /home/username/.ssh/id_rsa.pub: No such file or directory

That means the key is missing or the path was typed wrong. Double-check the command, and if needed, just go back and create the key again using the first command.
Also, if you accidentally run the command on the private key, and you see something like:

—–BEGIN RSA PRIVATE KEY—–

Then stop there. You are looking at the wrong file. Make sure you are using the public key file (id_rsa.pub), not the private one.

Add Your SSH Key to GitHub

Next, you will need to take the public key that you got from the last step and paste it into your GitHub account.
Follow the steps below on GitHub –

  • Log in to GitHub and navigate to the private repository where you want to give access.
  • Go to Settings from the top-right corner.
  • On the left menu, under the Deploy keys, click on the Add deploy key button.
  • Give your key a name in the Title box. You can name it something like “cPanel Access” or anything else.
  • Paste the full SSH key into the Key field.
  • If you want to push code from your cPanel to GitHub, make sure you tick the box that says Allow write access.
  • Finally, click on Add key to save it.

GitHub now knows it is safe to let your cPanel connect.

You will still be able to pull data from GitHub if you don’t tick the write access box. However, you won’t be allowed to push any changes back from your side. This setting determines whether you can push changes to the repository or simply clone it. Always check the box if you plan on pushing updates from your local machine.

Remember, refer to the documentation for how to add SSH keys if you are using a different hosting service like Bitbucket or GitLab.

Follow this guide how to add and delete SSH keys quickly.

Test the SSH Connection

To make sure everything is working, you should test your SSH setup.
Run this command:

ssh -T [email protected]

Replace example.com with your actual GitHub hostname or the host of the private repository.
You will get a message saying something like ‘You’ve successfully authenticated, but GitHub does not provide shell access.’ This confirms that your SSH connection to GitHub is working.

Clone the Private Repository

You are now ready to clone the private repository to your local system. To do this, use the following Git command:

git clone [email protected]:username/private-repository.git

Replace username with your GitHub username and private-repository with the actual name of your repository.

After this, your code should start downloading, and you will be all set.

So that’s how you can connect your cPanel server with a private Git repository using SSH keys. Once it is done, your setup will be secure and smooth to use.

Security Note: Never share your private SSH key. Only the public key should be shared when registering it with a repository host. If your private key is exposed, it compromises the security of your SSH access.

Conclusion

Setting up SSH access to a private Git repository comes down to four steps: generate a key, register it with your host, verify the connection, and clone. This same process works across GitHub, GitLab, and Bitbucket with only minor differences in where you add the key. Once set up, your cPanel-to-repository connection stays secure and authenticated without repeated logins.

Need to access your server’s command line first? See our guide on accessing the Terminal from WHM, or explore Server Management Services for expert support.

FAQs

What is a deploy key on GitHub?

A deploy key is an SSH key tied to a single repository instead of your whole GitHub account. It’s added under the repo’s Settings → Deploy Keys and can be given read-only or read/write access, making it ideal for server-to-repo connections like cPanel.

Why do I get “GitHub host key verification failed”?

This usually means your system doesn’t yet trust GitHub’s SSH fingerprint. Run ssh -T [email protected] once — if prompted to trust the host, type yes. This adds GitHub to your known_hosts file and resolves the error on future connections.

Why does Git say “remote repository not found”?

This typically happens when the repository URL is wrong, the repo is private and your SSH key isn’t authorized, or you’re using HTTPS instead of SSH without proper credentials. Double-check the clone URL and confirm your key has been added under Deploy Keys.

How do I check if I have write access to a Git repository?

Try a dry-run push with git push --dry-run. If it completes without a permission error, you have write access. Alternatively, check the repository’s Settings → Collaborators (or Deploy Keys, if using SSH) to see your access level directly.

Should I use SSH keys or a Personal Access Token?

SSH keys are better for long-term, passwordless server connections (like cPanel-to-GitHub). Personal Access Tokens (PATs) work over HTTPS and are useful when SSH ports are blocked or for quick, revocable access. Both are secure when set up correctly.

Can I use the same steps for GitLab or Bitbucket?

Yes – the SSH key generation and testing process is identical. Only the step of adding the key differs: GitLab uses Settings → SSH Keys, and Bitbucket uses Personal Settings → SSH Keys, instead of GitHub’s Deploy Keys section.

August 26, 2026