Since they require SSH access, you must perform additional steps in order to clone a privately-hosted remote repository.
- 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:
The output should match the below example, where AAAAB3Nza… indicates a valid SSH key:
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
- 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:
- Log in to your GitHub account.
- Go to your private repository.
- Click on Settings located in the top right corner of the page. This will display a new page.
- Click on Deploy keys, in the left side menu. This will display a new page.
- Click on Add deploy key, in the top right corner of the page. This will display a new page.
- 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.
- In order to push code from your cPanel account to your GitHub account, tick the Allow write access checkbox.
In case you don’t tick this checkbox, you can only make changes from your GitHub repository to the cPanel-hosted repository.
- 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 email@example.com
Clone the Repository
In order to clone the repository, execute the below command on the cPanel account, where firstname.lastname@example.org:MyStuff/private-repository.git indicates the private repository’s clone URL:
git clone email@example.com:MyStuff/private-repository.git
In this way, you can setup access to private repositories using Git.