How To Set Up a Private Git Server on a VPS

How To Set Up a Private Git Server on a VPS

How To Set Up a Private Git Server on a VPS

Setting up your own private Git server on a Virtual Private Server (VPS) can be a great way to manage your code and collaborate with others in a secure way. In this tutorial, we'll go through the steps to set up a private Git server on a VPS using SSH.

Prerequisites

  • A VPS with root access
  • SSH client

Step 1: Connect to Your VPS

Connect to your VPS using SSH:

ssh username@your_vps_ip_address

Step 2: Install Git

Update the package manager and install Git:

sudo apt update sudo apt install git

Step 3: Create a Git User

Create a new user for Git:

sudo adduser git

Step 4: Initialize Git Repository

Create a new directory for your Git repositories:

sudo mkdir /git

Initialize a new Git repository:

sudo git init --bare /git/my_project.git

Step 5: Set Permissions

Set the owner and group of the Git directory to the Git user:

sudo chown -R git:git /git

Step 6: Add SSH Key

Generate an SSH key on your local machine:

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

Copy the public key to the Git user's authorized_keys file:

sudo mkdir /home/git/.ssh sudo chmod 700 /home/git/.ssh sudo touch /home/git/.ssh/authorized_keys sudo chmod 600 /home/git/.ssh/authorized_keys cat ~/.ssh/id_rsa.pub | ssh git@your_vps_ip_address "sudo tee -a /home/git/.ssh/authorized_keys"

Step 7: Clone Repository

Clone the Git repository on your local machine:

git clone git@your_vps_ip_address:/git/my_project.git

Conclusion

Congratulations! You have now set up a private Git server on your VPS. You can now use this server to manage your code and collaborate with others in a secure way.

Keywords: Git, server

Комментарии

Популярные сообщения из этого блога

How To Modify CSS Classes in JavaScript

How To Backup MySQL Databases on an Ubuntu VPS

How To Backup PostgreSQL Databases on an Ubuntu VPS