

We’re assuming that Git package is already installed on your local machine.

The entire public key text should be on a single line. Use the following command: ssh-keygen -t rsa -b 4096 -C the output from the catĬommand above and go back to the Git server console.Īnd paste the public key that you copied from your local machine into the ~/.ssh/authorized_keys file: sudo nano /home/git/.ssh/authorized_keys The output should look something like the following: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDd/mnMzHwjUzK8g3ldfsfRpJuC16mhWamaXRk8ySQrD/dzpbRLfDnZsLxCzRoq+ZzFHGwcQlJergtergdHGRrO8FE5jl3IWRRp+mP12qYw= you get an error message saying No such file or directory, it means that you do not have an SSH key pair generated on your local machine. If you already have an SSH key pair created on your local system, you can display the public key by typing: cat ~/.ssh/id_rsa.pub To be able to push the local git changes to the Git server you’ll to add your local user SSH public key to the remote “git” user’s authorized_keys file. Initialized empty Git repository in /home/git/projectname.git/ The important thing is to create the repository under the “git” user home directory. Run the following command to initiate a new empty repository: git init -bare ~/projectname.git You’re now ready to create your first Git repository. Run the following commands to create the SSH directoryĬreate a file named ~/.ssh/authorized_keys which will hold the authorized users’ SSH keys: touch ~/.ssh/authorized_keys & chmod 0600 ~/.ssh/authorized_keys We did not set a password for the user “git”, the login will be possible only using the ssh keys. All the repositories will be stored under this directory. The user home directory is set to /home/git. That will manage the Git repositories: sudo useradd -r -m -U -d /home/git -s /bin/bash git If you are using Debian or Ubuntu, refresh the local package index and install gitīy running the following commands as sudo user: sudo apt update & sudo apt install git The first step is to install Git on your server. The Git server can be set up on any remote Linux machine or even on your local system. Otherwise, you should consider installing a self-hosted git application such as Gitea, Gogs

This setup is good if you have few repositories and the collaborators are tech-savvy. In this guide, we’ll explain how to set up a bare Git server on Linux. Setting up a Git Server allows you to create private repositories without the restrictions of the providers’ free plans.
