Knowledge Base
MilesWeb / cPanel

Learn to Set Up Access to Private Repositories Using Git

Approx. read time : 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:

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:

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

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:

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

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:

    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:


    In this way, you can setup access to private repositories using Git.
Avatar
Pallavi is a Digital Marketing Executive at MilesWeb and has an experience of over 4 years in content development. She is interested in writing engaging content on business, technology, web hosting and other topics related to information technology.
Need help? We’re always here for you.
Register Your Free Domain Name
OFFER EXPIRES IN
04
min
59
sec