How to set up access to private Git™ repositories

Git Banner

Overview

This document demonstrates how to set up a private repository on your localhost. This allows the user to use cPanel as an automatic deployment location for their project that can run PHP, Ruby, Node.js™, or other desktop applications.

Important:
  • This tutorial uses GitHub as an example host for a private repository. However, most of the steps in this tutorial are similar to the steps for any other private repository host.
  • The steps in this tutorial require the Shell Access setting in cPanel & WHM version 70 or earlier or the Shell Access & Terminal setting in cPanel & WHM version 72 or later.

 

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

  • This feature enforces several restrictions on clone URLs, and it verifies the remote host’s public SSH keys for ssh:// clone URLs. For more information, read the cPanel’s  Git Version Control documentation.
  • If you do not perform these steps, you may see errors that resemble the following examples:
    1. Error: (XID dugfmj) “/usr/local/cpanel/3rdparty/bin/git” reported error code “128” when it ended: fatal: could not read Username for 'https://github.com': No such device or address
    2. Error: “/usr/local/cpanel/3rdparty/bin/git” ended prematurely because it received the “TERM” (15) signal:

Set up access to private repositories

To set up access to private repositories, perform the following steps:

Generate an SSH key

If you have not already configured one, run the following command to generate an SSH key:

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

In this example, username represents the cPanel account username and example represents the domain name.

After you run this command, the system will prompt you to enter a passphrase. Do not enter a passphrase, and press Enter to continue.

Confirm that you generated the SSH key correctly

To confirm that the key exists and is in the correct location, run the following command:

cat ~/.ssh/id_rsa.pub

The output should resemble the following example, where AAAAB3Nza... represents a valid SSH key:

ssh-rsa AAAAB3Nza...
Important:

Retain the full SSH key. Step 3 requires it.

If the output resembles the following example, ensure that you entered it correctly, and then run the command in Step 1 again:

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

If the output resembles the following example, ensure that you ran the cat command with the correct path:

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

Register your SSH key with the private repository host

Note:

For information about how to register your SSH key with another private repository host, consult that host’s website or documentation. Some repository hosts, such as Bitbucket, do not allow you to configure write access for your access keys.

To register an SSH key with GitHub, perform the following steps:

  1. Log in to your GitHub account.
  2. Navigate to your private repository.
  3. In the top right corner of the page, click Settings. A new page will appear.
  4. In the left side menu, click Deploy keys. A new page will appear.
  5. In the top right corner of the page, click Add deploy key. A new page will appear.
  6. In the Title text box, enter a display name for the key.
  7. In the Key text box, paste the entire SSH key.
  8. If you want to push code from your cPanel account to your GitHub account, select the Allow write access checkbox.
    Note:
    If you do not select this checkbox, you can only deploy changes from your GitHub repository to the cPanel-hosted repository.
  9. Click Add key.

Test the SSH key

To test your SSH key, run the following command, where example.com represents the private repository’s host:

ssh -T git@example.com

Clone the repository

To clone the repository, run the following command on the cPanel account, where [email protected]:MyStuff/private-repository.git represents the private repository’s clone URL:

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