Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  cPanel  >  Learn to Set Up Access to Private Repositories Using Git
Top Scroll

Learn to Set Up Access to Private Repositories Using Git

 3 min

Overview

Since they require SSH access, you must perform additional steps in order to clone a privately-hosted remote repository.

 

Important:

  • In this tutorial GitHub is used as an example host for a private repository. But, most of the steps in this tutorial are similar to the steps for any other private repository host.
  • You will need the Shell Access feature in cPanel & WHM version 70 or earlier or the Shell Access & Terminal setting in cPanel & WHM version 72 or later.
  • It is appropriate to use cPanel’s Terminal interface (cPanel >> Home >> Advanced >> Terminal) to access the command line from within the cPanel interface.
  • Due to this feature several restrictions are implemented on clone URLs, and it verifies the remote host’s public SSH keys for ssh:// clone URLs. For more information, read the Git Version Control documentation.

Steps to Set up Access to Private Repositories

Step 1: Generate An SSH Key

In case, you have not already configured one, run the below command to generate an SSH key:

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

Here the username indicates the cPanel account username and example indicates the domain name.

After executing this command, the system will ask you to enter a passphrase. Do not enter a passphrase, but just press Enter to continue.

Step 2: Confirm that the SSH Key Generated is Correct

For confirming that the key exists and is in the correct location, execute the below command:

cat ~/.ssh/id_rsa.pub

The output should match the below example, where AAAAB3Nza… indicates a valid SSH key:

ssh-rsa AAAAB3Nza...
 

Important:
Note the full SSH key as you will need it in Step 3.

If the output matches the below example, check that you entered it correctly, and then execute the command in Step 1 again:

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

If the output matches the below example, ensure that you executed the cat command with the correct path:

----BEGIN RSA PRIVATE KEY-----
AQKCAgByFAHL2301vtIuUQ+jy7+6MoHlXwa0G7Ob/R1KOthYw3KMr/cCQycZimcZ

Step 3: Register Your SSH Key with the Private Repository Host

 

Notes:

  • To learn about how to register your SSH key with another private repository host, contact that host or check for their documentation.
  • Some repository hosts, such as Bitbucket, won’t allow you to configure write access for your access keys.

Follow the below steps to register an SSH key with GitHub:

      1. Log in to your GitHub account.
      2. Go to your private repository.
      3. Click on Settings located in the top right corner of the page. This will display a new page.
      4. Click on Deploy keys, in the left side menu. This will display a new page.
      5. Click on Add deploy key, in the top right corner of the page. This will display a new page.
      6. Then enter your SSH key data:
        • In the Title text box, type a display name for the key.
        • In the Key text box, paste the entire SSH key.
      7. In order to push code from your cPanel account to your GitHub account, tick the Allow write access checkbox.
     

    Note:
    In case you don’t tick this checkbox, you can only make changes from your GitHub repository to the cPanel-hosted repository.

    1. Click Add key.

    Test the SSH Key

    Run the below command to test your SSH key, where example.com represents the private repository’s host:

    ssh -T git@example.com

    Clone the Repository

    In order to clone the repository, execute the below command on the cPanel account, where git@example.com:MyStuff/private-repository.git indicates the private repository’s clone URL:

    git clone git@example.com:MyStuff/private-repository.git

    In this way, you can setup access to private repositories using Git.

For our Knowledge Base visitors only
Get 10% OFF on Hosting
New Year Savings
30
MINS
59
SECS
Claim the discount before it’s too late. Use the coupon code:
STORYSAVER
Note: Copy the coupon code and apply it on checkout.