This guide will walk you through the process of performing system updates, installing Git, generating an SSH key pair, copying the public key to GitHub, cloning a repository, and troubleshooting common issues.
NOTE: This guide uses AlmaLinux OS
1. Perform System Updates #
Before making any changes or installing new software, it’s crucial to ensure that your system is up-to-date.
yum -y update
yum clean all

2. Install Git #
Git is a version control system that allows you to track changes in your code and collaborate with others. To install Git on your server, run the following command:
yum -y install git

This command installs Git and all its dependencies.
3. Generate an SSH Key Pair #
SSH keys provide a secure way to log into your server and authenticate with GitHub without using a password. To generate an SSH key pair, use the following command:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Replace "[email protected]"
with your email address. This command creates a 4096-bit RSA key pair.

4. Copy the Public Key to GitHub #
After generating the SSH key pair, you need to copy the public key to GitHub to enable secure communication between your server and GitHub.
Change to the .ssh
directory:
cd ~/.ssh
Display the public key using the cat
command:
cat id_rsa.pub

Copy the output, which is your public key.
Log in to GitHub and navigate to Your Profile > Settings > SSH and GPG Keys.
Click on the New SSH Key button.

Give the key a descriptive title and paste the public key into the Key field.
Click Add SSH Key to save it

5. Clone Your Repository on Your Server #
Once the SSH key is set up, you can clone your repository to your server.
Navigate to the directory where you want to clone the repository
cd /var/www/domain.com/public_html
Clone the repository:
git clone [email protected]:username/repo-name.git .
Replace username
and repo-name
with your GitHub username and repository name, respectively.

6. Reload Your Site #
After cloning the repository, your site should now load with the content from the repository. Access your site to confirm it is now accessible.

If you make changes locally and push them to the remote repository, you can pull the latest changes to your server using:
git pull origin main
Replace main
with the branch name you want to pull (e.g., master
or another branch).
7. Conclusion. #
Congratulations. You’ve successfully deployed your application to the VPS server using Git.
Happy Hosting.