DEV Community

Md. Hazzaz Bin Faiz
Md. Hazzaz Bin Faiz

Posted on

Deploy private git repository to shared hosting

Using git in shared platform, developer can deploy latest update easily to shared hosting.

If the repository is private, you need to do some extra work to deploy.

Before setting up git repository in server, you need to import passwordless SSH key to your server.

To generate SSH key run ssh-keygen -t rsa -b 4096 -f id_rsa
Press enter twice to generate passwordless key pair.

It will generate two file, id_rsa and id_rsa.pub

Log in to cpanel and navigate to SSH Access under SECURITY category.
image

Now click to Manage SSH Keys button.
image

To import your generated SSH key, click on Import Key button.
image

Now copy the content of id_rsa file generated before and paste it to the textbox labeled with, Paste the private key into the following text box:.

Now copy the content of id_rsa.pub file generated before and paste it to the textbox labeled with, Paste the public key into the following text box:.

Leave the password field empty and click on Import button.

Now we need to tell GitHub about our public key.

Go to repository setting and navigate to Deploy keys section and click Add deploy key button to import your generated public key.

A for will appear, give this key a Title as you want and paste content of id_rsa.pub file in key textbox.

Deploy keys always have pull access by default. If you like to push changes from your server, check Allow write access checkbox.

Click Add key button to add this key as deploy key.

Now your server can pull from this private repository.

To deploy your repository to your server. Go to cpanel and navigate to Gitβ„’ Version Control under FILES category.

Click on Create button, copy SSH clone url from GitHub and paste it to Clone URL textbox.
image

Give a Repository Path where you want to clone the repository and Repository Name as you like.

Click on Create button to create the repository.

Your server will clone the repository to the Repository Path you have given during repository creation.

Have Fun πŸŽ‰

Top comments (2)

Collapse
 
sreenitherocker profile image
sreenitherocker

Error: (XID psjyjh) β€œ/usr/local/cpanel/3rdparty/bin/git” reported error code β€œ128” when it ended: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

Facing above error

Collapse
 
hazzazbinfaiz profile image
Md. Hazzaz Bin Faiz

Check your SSH key