Setup GIT server

This post describes how to setup your ubuntu server as a GIT server. Clients are able to clone repositories and push their changes back to the server with this setup. We make use of ssh in combination with the git-shell to provide extra security.git

On your GIT server execute the commands below:

If you use a Synology server add the following line to your /etc/shell file:

Create a bare GIT repository on the server at /opt/git:

Now on your local machine create a repository  and push it to the server:

To clone the repository to your local development machine execute the following commands:

When you have made changes to a file you want to undo (revert changes back to the last commit) execute the command below:

GIT and SSH public / private key

If you want to use git with a SSH key follow these steps. A SSH key is a convenient (and very secure!) way to login to your server. First create a public / private key pair with the command (-t is the type of encryption and -C is a comment):

Protect this key with a strong passphrase. After the key is generated you have to copy the public part to the server. Off course this should also be done in a secure way so use the ssh-copy-id tool for this. Execute the command:

The ssh_agent will ask for your passphrase (not the user password) and remember it. If you don’t have a ssh_agent enabled you could do without the passphrase but that is a bit less secure.


Leave a Reply

Your email address will not be published. Required fields are marked *