To clone a private repository, you must use an SSH key pair and the SSH protocol in the clone URL. If you try to clone a private repository using Git Version Control which is available in cPanel, it will return an error message following:
Error: (XID xna4yx) “/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
Requirements
- Must have Git Version Control Option in cPanel.
Files -> Git Version Control
- Must have Terminal Access
Advanced -> Terminal
If your cPanel doesn’t have an enabled feature, You can request your hosting provider to enable it.
Steps
Create an SSH Key Pair
At first, you are required to create an SSH Key Pair without a password and that can be generated from the terminal.
- Go to Terminal and type
ssh-keygen -t rsa
- Then, It will ask to Enter the file in which to save the key:
- Click
Enter
- It will ask for the passphrase
Enter passphrase (empty for no passphrase):
- Click
Enter
Enter same passphrase again:
- Click
Enter
- Now, You will see the successful message:
Your identification has been saved in xxxxxxx
Your public key has been saved in xxxxxxx
The key fingerprint is: xxxxxxx
- Copy the public key from the saved path.
- And you are done 🙂
Add the public key to the Git provider
- Open your repository in Git Provider.
- Go to Settings
- Check for the Deploy keys option.
- Click Add Deploy key
- Add a Random title and paste the public key which was copied from cPanel.
- Click on Add key
How to add an SSH key to GitHub?
- GitHub: Please visit https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account
- GitLab: Please visit https://docs.gitlab.com/ee/ssh
- Bitbucket: Please visit https://confluence.atlassian.com/bitbucketserver/enable-ssh-access-to-git-repositories-776640358.html
Test the Connection
Go to Advanced -> Terminal
and type the following command:
- GitHub:
ssh -vT git@github.com
- GitLab:
ssh -vT git@gitlab.com
- Bitbucket:
ssh -vT git@bitbucket.org
Once you verify that the SSH connection is working, you are ready to clone the private repository using the ssh:// protocol
.
Clone the Private Repository
- Go to
Git Version Control
- Click
Create
- In the Clone URL text box, type the URL of the repository to clone
- Type the path to the document root of the site in the Repository Path text box
- Type the name of the Repository in the Repository Name text box
- Click
Create