Introduction
This guide provides a step-by-step explanation for configuring key authentication to access a remote Git repository from your cPanel account. If you have not created an SSH key yet, you can use the steps in this article:
How to generate an SSH Key using the command line
You would use this guide if:
- You need to clone a remote Git repository into your cPanel account and the remote repository requires authentication.
- You need to pull changes from a remote Git repository to the repository that is hosted in your cPanel account and the remote repository requires authentication.
- You see a Permission Denied error in the cPanel Git™ Version Control icon
Procedure
- Create the SSH configuration file if it does not yet exist:
touch ~/.ssh/config
- Update the permissions of the ~/.ssh/config file to 0600:
chmod 0600 ~/.ssh/config
- The ownership should already be set to the cPanel user if you're doing this as the cPanel user, but it is ideal to ensure that is the case:
chown cpanelusername:cpanelusername ~/.ssh/config
- Open ~/.ssh/config with the text editor of your choice and enter a configuration formatted according to the following example.
Host remote-git-repo-domain.tld
IdentityFile ~/.ssh/my_key
User remoteusername -
NOTE: If you want to use this private key when connecting to any remote host via SSH, you may use an asterisk character as the Host instead of a specific domain name: *
Otherwise, use the domain name of your remote Git repository provider, which would be found within the SSH repository URL that you obtain in step 7 below.
Be sure to also use the path to your private key for the IdentityFile, and replace remoteusername with the username used for the git repository.
- Save the file
- Login to the management interface of your remote Git repository
- Obtain the SSH repository URL that you would like to clone your repository from.
- While you are in the management interface of your remote Git repository, ensure that you configure the public key within the remote system so that it is authorized for access. To do this, cat the contents of the public key from your cPanel Terminal or SSH session with the following command: (be sure to use the path to your own public key that you generated in step 2)
cat ~/.ssh/my_key.pub
- Then paste the output from that command into the remote Git repository interface where key authentication is supposed to be configured.
- Back in your cPanel Terminal or SSH session, perform a test clone of the repository to see if authentication will work properly. The following examples use the --bare option in case you have a large repository, and do not want to download all the data. Use the SSH repository URL that you obtained from your Git provider from step 7 above. # GitHub style SSH clone URL
git clone --bare --verbose git@github.com:githubusername/repo-name.git -- ~/test-clone-destination-dir # Standard SSH clone URL
git clone --bare --verbose ssh://remoteusername@remote-git-repo-domain.tld:SSHPort/path/to/repo.git/ -- ~/test-clone-destination-dir
- If authentication did not work, you should double-check your ~/.ssh/config, and troubleshoot the SSH access to the remote server. You may also need to check the permissions and ownership of the ~/.ssh directory and any files contained within it. If the remote Git host supports direct SSH logins (GitHub does not) you may try using an SSH command similar to the following to debug the authentication issue:
ssh -vvv -p SSHPort remoteusername@remote-git-repo-domain.tld
- If authentication was successful, you may then configure your repository within the cPanel Git™ Version Control icon.