Setup Git on a Server
First, ssh or otherwise login to your remote server:
Next, install git on the server.
sudo apt update && sudo apt install gitNext, create a new user that will manage the Git Repos:
sudo useradd -r -m -U -d /home/git -s /bin/bash gitSwitch over to the git user with sudo su
sudo su - gitMake the folder you want to in the home directory:
mkdir project_name.gitNext, make the ~/.ssh directory for the user and set the correct
permissions:
mkdir -p ~/.ssh && chmod 0700 ~/.sshNext, create the authorized keys file and set it to have permissions of
0600.
touch ~/.ssh/authorized_keys && chmod 0600 ~/.ssh/authorized_keysNext, move your ssh keys to the server’s authorized keys:
On your local machine:
cat ~/.ssh/id_rsa.pubAnd copy paste it into the authorized keys file:
sudo vim /home/git/.ssh/authorized_keysnow add your git remote to the local repository you took the rsa key from:
git remote add server git@{server_ip}:project_name.gitand push!
git push -u server master