DEV Community

loading...

Deploy private git repository to shared hosting

hazzazbinfaiz profile image Md. Hazzaz Bin Faiz ・2 min read

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 πŸŽ‰

Discussion (0)

pic
Editor guide