Integrating Private GitHub Repositories with a VPS Server

  • Make a Github repo, and push the code to the repo.

  • Login to the server by SSH

  • Check if git is installed or not at the server, if not

    •   sudo apt update
        sudo apt install git
      
  • Generate an SSH key on the VPS server,

    • To establish a secure connection between your VPS server and GitHub, you'll need to generate an SSH key on the VPS server.

    • Run the following command on your VPS server:

    •   ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
      

      replace your_email with your email

  • Add the SSH key to your GitHub account

    •   cat ~/.ssh/id_rsa.pub
      

      copy the key.

    • Go to Your Github Repo

    • Click on the Settings Tab

    • Click on the Deploy Keys option from the sidebar

    • Click on Add Deploy Key Button and Paste Remote Server's Copied SSH Public Key then Click on Add Key

      you can add "ssh" as the Title and paste the key copied into Key

  • Verify the Connection

    • Go to Your Server Terminal then run below

    •   ssh -T git@github.com
      
    • If this message comes, Are you sure you want to continue connecting (yes/no/[fingerprint])? enter yes.

    • It will show you the repo name.

  • Clone Project from your GitHub account

    • Copy the SSH link

    • and add it with git clone, like this

      git clone git@github.com:wevlu/backend.git

  • Run ls command to verify that the project is present.

Done.

Did you find this article valuable?

Support Nishant Kumar by becoming a sponsor. Any amount is appreciated!