Knowledge Base

Set Up SSH Access to Private Repositories in cPanel

 Log in to your cPanel.
 Open the Terminal or connect to your server via SSH.

  • Connect to Your Server

- Log in to your server using SSH, or
- Open cPanel and access the Terminal

 

  • Generate an SSH Key

Run the following command:

ssh-keygen -t rsa -f ~/.ssh/repo -b 4096 -C "username@example.com"

Notes:
- Replace "repo" with the repository name.
- Replace "username@example.com" with your cPanel email.
- When prompted for a passphrase, leave it empty and press Enter.

This command will generate:
- A private key: ~/.ssh/repo
- A public key: ~/.ssh/repo.pub

 

  • Create and Configure the SSH Config File

1- Create the SSH config file:

touch ~/.ssh/config

2- Set correct permissions:

chmod 0600 ~/.ssh/config

3- Open ~/.ssh/config using a text editor and add the following:

Host remote-git-repo-domain.tld
IdentityFile ~/.ssh/repo

Notes:
- Replace remote-git-repo-domain.tld with the Git provider domain (for example: github.com).
- You may use * instead of a domain name to apply the key to all SSH connections.
- Ensure the IdentityFile path matches the private key created earlier.

Save the file.

 

  • Register the SSH Key with the Repository Host (GitHub Example)

1- Log in to your GitHub account.
2- Navigate to the private repository.
3- Click Settings.
4- From the left menu, select Deploy keys.
5- Click Add deploy key.
6- Enter a title for the key.
7- Paste the contents of the public key file:
~/.ssh/repo.pub
8- (Optional) Enable Allow write access if push access is required.
9- Click Add key.

 

  • Test the SSH Connection

Run the following command:

ssh -i ~/.ssh/repo -T git@github.com

If configured correctly, you will receive a successful authentication message.


  • (Optional) Configure Multiple Repositories

If you use multiple repositories, create a separate SSH key for each one and define them in ~/.ssh/config.

Example:

Host github.com-project1
Hostname github.com
IdentityFile ~/.ssh/project1

Host github.com-project2
Hostname github.com
IdentityFile ~/.ssh/project2

 

  • Clone a Private Repository

Single repository:

git clone git@github.com:username/repo.git

Multiple repositories (using SSH config alias):

git clone git@host-alias:username/repo.git

 

 
Please rate this article to help us improve our Knowledge Base.

0 0