How to set up access to private repositories using Git:

Generate An SSH Key :-

  • ssh-keygen -t rsa -b 4096 -C “username@example”
  • Here, the username indicates the cPanel account username, and example indicates the domain name.
  • After executing this command, the system will ask you to enter a passphrase. Do not enter a passphrase; simply press Enter to continue.

Confirm that the SSH Key Generated is Correct :-

  • To place the SSH key in the correct location, execute the command below
  • cat ~/.ssh/id_rsa.pub
  • The output should match the below example:
  • ssh-rsa AAAAB3Nza…

Register Your SSH Key with the Private Repository Host :-

  • Follow the steps below to register an SSH key with GitHub :-
  • Log in to your GitHub account.
  • Go to your private repository.
  • Click on Settings located in the top right corner of the page, leading to a new page.
  • Navigate to Deploy keys in the left side menu, bringing up another page.
  • Click on Add deploy key in the top right corner, leading to a new page.
  • Enter your SSH key data:
    • In the Title text box, type a display name for the key.
    • In the Key text box, paste the entire SSH key.
    • To push code from your cPanel account to your GitHub account, tick the Allow write access checkbox.

Click Add key :-

  • Test the SSH key by running the command below:
  • ssh -T git@example.com

Clone the Repository :-

  • To clone the repository, execute the command below on the cPanel account, where git@example.com /private-repository.git represents the private repository’s clone URL:

git clone git@example.com:MyStuff/private-repository.git

  • This setup enables access to private repositories using Git.

Was this article helpful?

Related Articles