To clone a privately-hosted remote repository to your cPanel server, you need to ensure that your hosting package has SSH enabled. However, customers on Web Hosting Magic need not worry as every hosting package comes with SSH access. Additionally, you must perform some extra steps for successful cloning.
You have various options for accessing the command line interface. You can use cPanel's Terminal interface, which is located at cPanel >> Home >> Advanced >> Terminal. Alternatively, you can use any tool that allows you to access the cPanel server via SSH, or your local system's Terminal.
Step 1: Generate An SSH Key
To begin, we need to generate an SSH key for authorization. Previously, we could use RSA keys with SHA-1. However, according to Github's security blog, RSA keys with SHA-1 are no longer accepted due to security concerns. To create a new SSH key with ECDSA encryption and add it to Github, use the following command.
ssh-keygen -t ecdsa -b 521 -C [email protected]
In the given scenario, the term "username" refers to the cPanel account username, while "example" denotes the domain name. When you execute this command, the system will ask you to provide a passphrase. It is important to note that you should not enter any passphrase. Press Enter to continue.
Step 2. Verify Generated The SSH Key
You can verify the existence and correct location of the key by running the following command:
Step 3. Register Your SSH Key With The Private Repository Host
If you need help registering your SSH key with a private repository host such as Bitbucket or GitLab, you can refer to their respective websites or documentation.
Note that some repository hosts, like Bitbucket, may not allow you to configure write access for your access keys.
To register your SSH key with GitHub, follow these steps:
- Sign in to your GitHub account.
- Go to your private repository.
- Click on "Settings" in the top right corner of the page to access a new page.
- In the left-hand side menu, select "Deploy keys" to access a new page.
- Click "Add deploy key" in the top right corner of the page to access a new page.
- Enter the following details for your SSH key:
• In the "Title" text box, give your key a display name.
• In the "Key" text box, paste your entire SSH key. If you want to be able to push code from your cPanel account to your GitHub account, select the "Allow write access" checkbox. It is important to note that if you do not select this checkbox, you will only be able to deploy changes from your GitHub repository to the cPanel-hosted repository.
- Click "Add key".
- In the "Key" text box, paste the entire SSH key. If you want to push code from your cPanel account to your GitHub account, select the "Allow write access" checkbox. Do note that if you do not select this checkbox, you can only deploy changes from your GitHub repository to the cPanel-hosted repository.
- Click "Add key" to complete the process.
Step 4 : Test Out The SSH Key
To check if your SSH key is working properly, execute the following command:
ssh -T [email protected]
Step 5: Clone The Private Repo
To clone the private repository onto your cPanel account, use the following command:
git clone [email protected]:$name/private-repo.git
Note that "[email protected]:$name/private-repo.git" is the clone URL for the private repository.
If you encounter the error message "Error: The WebSocket handshake failed at..." while accessing cPanel's Terminal interface (cPanel >> Home >> Advanced >> Terminal), double-check your connection.
If you are currently using a VPN, disconnect from it and use your regular internet connection instead.