August, 21 2023
I have been running Litehost as a side project since 2019 and my focus is on making the platform very friendly for Laravel projects. If you want to learn how to deploy Laravel to your Cpanel account you can checkout my blog post here — How To Deploy A Laravel Project On Linux Shared Hosting In 5 Minutes
But the blog post above only talked about Laravel in a public repository. In this post, I will show you how to connect your Github, Gitlab, or Bitbucket account to your Cpanel and deploy your code without making it public.
Let's jump in...
Login into CPanel via ssh or open the CPanel web terminal, and generate public and private keys using the commands below:
cd ~/.ssh && ssh-keygen -t ecdsa -b 521 -C "email@example.com"
For the sake of this example, follow the prompts and use the defaults you are presented with. This command will generate a private key (id_ecdsa) and a public key (id_ecdsa.pub) inside the /home/yourCpanelUsername/.ssh directory.
To authorize this key we need to run this command:
cat ~/.ssh/id_ecdsa.pub >> ~/.ssh/authorized_keys
This command will add the public key to the list of authorized keys on the CPanel server.
We need to copy the public ssh key by running this command on the CPanel terminal:
This will echo the public key on the terminal (copy it).
To add the public key to Github, we have to log into your Github, and navigate to SSH and GPG Keys in your github settings page. Add a new SSH key by pasting the public key we copied and save.
Run the command below to confirm Github authorization:
ssh -T firstname.lastname@example.org
This will ask you to confirm a confirmation question, choose yes and you will get a successful message that reads something like this — Hi *githubusername**! You've successfully authenticated, but GitHub does not provide shell access.*
Following the same steps we did for Github Authorization, we just have to add the public key to our Gitlab account and test the authorization by running this command:
ssh -T email@example.com
You will get a message that reads — Welcome to GitLab, @gitlabusername!
Following the same steps we did for Github Authorization, we just have to add the public key to our Bitbucket account and test the authorization by running this command:
ssh -T firstname.lastname@example.org
You will get a message that reads — You can use git to connect to Bitbucket.
Now you can clone your private repositories without having to make them public. Bravo!
Be the first to hear about anything I publish, launch, or think is helpful for you. Subscribe here
Litehost is a web hosting platform for PHP & Laravel developers with Composer, Git, PHP & CLI pre-installed. Try it now