Table of Contents

This tutorial will show how you can set up an SSH key on your cPanel server to clone your private GitHub repositories securely. You are going to create an SSH key unique for your server, add it in your GitHub account, and edit some SSH settings so you test the connection and easily clone all your repositories with just a single action, avoiding any repetition of entering your password every single time. This approach facilitates smooth, secure access to private repositories for maintaining code at your server.
Steps Involved to Clone All Private Multiple Git Repositories through cPanel
1. Create SSH Key
- Go to cPanel > Terminal and execute:
ssh-keygen -t rsa -f ~/.ssh/REPOSITORY_NAME -b 2048 -C “CPANEL_USERNAME@CPANEL_DOMAIN:2083” - Replace REPOSITORY_NAME, CPANEL_USERNAME, and CPANEL_DOMAIN with your respective repository name, cPanel username, and domain.
2. Copy the Public Key
- cPanel > SSH Access > Manage SSH Keys.
- Copy the Public Key generated for REPOSITORY_NAME.
3. Add Key to GitHub
- In your GitHub account go to the Settings of your repository > Deploy Keys.
- Click Add Key, paste the copied public key and check Allow write access if needed.
4. Create SSH Config File
- Create or edit the config file in the ~/.ssh folder: nano ~/.ssh/config
Add the following:
Host REPOSITORY_NAME.github.com
Hostname github.com
IdentityFile ROOT_PATH/.ssh/REPOSITORY_NAME User git - Replace REPOSITORY_NAME with the repository name and ROOT_PATH with the full path to your.ssh folder.
5. Test SSH Connection
- Test using:
ssh -i ~/.ssh/REPOSITORY_NAME -T git@github.com - Expected output:
Hi <username/repo_name>! You’ve successfully authenticated, but GitHub does not provide shell access.
6. Clone the Repository
- Use cPanel > Git Version Control to clone the repository:
- Clone URL: ssh://REPOSITORY_NAME.github.com/GIT_USERNAME/REPOSITORY_NAME
- Replace REPOSITORY_NAME and GIT_USERNAME by your repository and GitHub username.
7. Repeat for Multiple Repositories
- For each private repository, repeat steps 1–6, making sure you:
- Create one SSH key per repository
- Add an entry in the ~/.ssh/config file corresponding to each repository
- Use the corresponding Clone URL in the Git Version Control section.