Automatically Deploy Git Repo Into cPanel — Part 1 Add SSH Key

Md. Hasnain
4 min readOct 8, 2021

--

If you were manually uploading your files to public_html until now, you know how boring and time killing it can be. Follow this easy article and you are over that! Don’t worry if you are a beginner or not!

This article id divided into 2 part and an option part 3. In part-1 we will add cPanel’s ssh key to git. In part-2 we will clone our git repo into cPanel and deploy it into public_html. In part-3(optional) we will setup development and production environment for our project.

Step 1: Generate ssh key pair in cPanel

1.1 From cPanel click “SSH Access”. Normally it is located under Security

1.2 In the next screen click “Manage SSH Keys”

1.3 In the next screen click “Generate a New Key”.

1.4 You will see a simple form. Insert the Key Name and Key Password and click “Generate Key”. I will suggest to store this password somewhere (optional).

1.5 If the key is generated successfully you will see something like that. Click on “Go Back” or simply return to “Manage SSH Key” page.

1.6 You should see your newly generated key name under Public Keys. If you see “not authorized”, simply click on “Manage”

1.7 In the next screen just click “Authorize”, and it will be authorized.

1.8 Now if you go back to previous page, you should see the key is authorized. Click on “View/Download” button to copy the public key.

1.9 In the next screen just copy the key. And we are done!

Step 2: Add ssh public key to git.

For this article I will use Github. But you can use gitlab, bitbucket etc too. I assume you already have your project into git. If not, follow this link.

2.1 Now, inside Github repo select the settings tab. Select Deploy keys from the left panel. You can see there is an “Add deploy key” on the top right corner. Click on it.

2.2 Add any Title and paste the Key that you copied from your cPanel. And then press “Add Key” button.

2.3 And all done! The key should be listed like below.

Thats all for this article! In Part-2 we will clone our git repo into cPanel and deploy it into public_html. Follow the link below for Part-2.

--

--

Md. Hasnain

Programming is my hobby and Android is my passion :) . I am a professional Mobile Application Developer(Native and cross platform).