Clone Github Repository to VPS Server

Guide to Clone Repository Github on VPS Server

Explain Clone GitHub Repository on VPS

Learn how to clone a GitHub repository on a VPS with this step-by-step guide. Perfect for developers and beginners. As we know, there are some common types of jobs like devops, front end developers, backend developers and fullstack developers. Each has rather challenging job descriptions in its field. But nowadays, the average developer is claimed not only to have one area of expertise, for example, me as a fullstack developer should be able to set up servers for application production needs.

This time I’m going to give you a simple tutorial so you can integrate git into a vps server, you don’t need to have special skills as a devops, even if it’s not a problem if you want to learn how to be a devops.
Yesterday I just gave you a tutorial on how to install nginx on vps servers and setup the block server of Nginx, and now we’re going to discuss jointly the integration of the github repository into the vps server.

Condition

The main condition is that you already have to install the web server first as an example I use nginx, please look at the following tutorial if you have not installed and blown it:

  1. How to Install Nginx on Ubuntu Server
  2. How to Setup Server Blocks NGINX

If so, let’s move on to the next step.

Step 1 – Check and Install Github Version

By default, if you are using Ubuntu Server OS, definitely Git is already installed, you can check it by type:

git --version

#the output below

git version 2.34.1

If your vps doesn’t have a git, you can installed:

#remember to update your ubuntu package first
sudo apt update

sudo apt install git

you can type that script above if you want to update it to newest version.

Step 2 – Configure Github and SSH Keys

After you install and updating your git in vps server, you must be want to clone your project into your vps server. But i suggest you to not again using https method, is it more secure if you using SSH Keys. Okay, for now you have to configure your account on vps.

git config --global user.name "Your Username"
git config --global user.email "youremail@domain.com"

Remember your username and your email at Github Account. Now check your github account on vps by typing:

git config --list

The output should like this:

Output
user.name=Your Username
user.email=youremail@domain.com
...

Awesome!, that is good. Now a little bit more to complete this tutorials. Next you have to generate ssh keys into your github account:

ssh-keygen

#enter it until you get this output below
Your identification has been saved in /your_home/.ssh/id_rsa
Your public key has been saved in /your_home/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:/hk7MJ5n5aiqdfTVUZr+2Qt+qCiS7BIm5Iv0dxrc3ks user@host
The key's randomart image is:
+---[RSA 3072]----+
|                .|
|               + |
|              +  |
| .           o . |
|o       S   . o  |
| + o. .oo. ..  .o|
|o = oooooEo+ ...o|
|.. o *o+=.*+o....|
|    =+=ooB=o.... |
+----[SHA256]-----+

Now copy your server ssh keys:

cat ~/.ssh/id_rsa.pub

#it will give output
#example

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCkfOjCcNN2T/hpTspBxm9nX+yVQSgK8g8Xw3P05694aWG7HXH2I+jJDp7e+pVlyh2Appn/FBcjkB1wUy79+xnqUUwF6RiW6nZkWlbtfyDVBpU2ini659cpOUceXpSZpon42SQwXmd4W5phI5wu91VN+sl5U= user@user

copy your ssh keys from word ssh-rsa to user@user, and login to your github account in browser then click your image profile then choose Settings menu

on left sidebar you will see SSH and GPG keys, click that menu.

Click New SSH key button and paste your ssh keys from vps server.

Step 3 – Clone Repository from Github

Yes!, its good to know youre Github Repository is connected with your vps server. Now is a last step to clone your project on VPS server. Change your directory into your main or root folder like this:

#i already setup my app folder here
cd /var/www/app/

Never forget to change your ownership into your server user:

#setup owner 
sudo chown -R $USER /var/www

Last, clone your repository:

#clone repository yang SSH
git@github.com:User/repository.git

Its great!, now you’ve done well to integrate your project into your vps server. But this isn’t over yet, because in next article we will setup CI/CD (Continous Integration/Continous Delivery) by using Github Workflows.

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply

    Your email address will not be published. Required fields are marked *