
The Remote is Git’s network backup system. GitHub is nothing more than a Remote manager with a Web interface. The connection uses the SSH protocol.
Installing Git on the Server
sudo apt-get install git
Creating the Git User
The “git” user will allow us to interact with the remote repository.
sudo adduser --system --shell /bin/bash --group --disabled-password --home /var/git/ git
Then change the owner of the “/var/git” directory, which was created during git installation and is the home directory of the git user.
sudo chown git:git /var/git
Configuring SSH Access for This User
Generate the SSH key for the git user.
ssh-keygen -t rsa
Select the default key storage directory. The “id_rsa” file contains the private key and the “id_rsa.pub” file contains the public key. Change the access permissions for the private and public keys.
sudo chmod 755 ~/.ssh
sudo chmod 600 ~/.ssh/id_rsa
sudo chmod 644 ~/.ssh/id_rsa.pub
Then copy the public key to a new “authorized_keys” file and modify its access permissions.
cp ~/.ssh/id_rsa.pub /var/git/.ssh/authorized_keys
sudo chmod 644 ~/.ssh/authorized_keys
Testing
To test the SSH connection, simply connect to the git user with an SSH client:
Creating the Repository
sudo mkdir /var/git/my-repo.git
sudo cd /var/git/my-repo.git
sudo git init --bare
sudo chown -R git:git /var/git/my-repo.git
Here, we create the directory that will contain the project, initialize the git project (the –bare argument indicates that the repository is empty) and change the project’s owner.
Cloning and Committing to the Remote
git clone [email protected]:my-repo.git
A message indicating that the cloned repository is empty will appear.