I recently got my own VPS, and decided to start using it as a Git server. It’s a Linux server running Centos 6. This tutorial assumes some knowledge of basic Linux commands.
As root or a user with sudo permissions, first thing is to install the dependencies Git will need:
$ yum -y install zlib-devel openssl-devel cpio expat-devel gettext-devel
Then change directories ready to wget Git:
$ cd /usr/local/src
$ wget http://git-core.googlecode.com/files/git-1.7.9.tar.gz
Untar it and change directory:
$ tar xvzf git-1.7.9.tar.gz $ cd git-1.7.9
Configure a make file, then install Git:
$ ./configure $ make $ make install
That’s it, Git is installed!
Next you will need to add a user called git, and give them a password:
$ adduser git $ passwd git
Now switch to your local machine and check if you have a public SSH key:
$ ls ~/.ssh/id_rsa.pub
If you don’t, run
to generate a public/private key pair. Then copy it to the git users home directory on your server:
$ scp ~/.ssh/id_rsa.pub firstname.lastname@example.org
Connect to your server via ssh again, and copy the key to the Git users authorised keys:
$ cd /home/git/ $ mkdir -p .ssh $ cat id_rsa.pub >> .ssh/authorized_keys
The restrict the permissions for .ssh and it’s contents:
$ chmod 700 .ssh $ chmod 400 .ssh/authorized_keys
Passwordless SSH is now setup. You should be able to connect from your local machine like this:
$ ssh git@[your server name]
Once connected as the git user, you can setup your first Git repo:
$ mkdir testproject.git $ cd testproject.git $ git init --bare
‘Bare’ means that the repo will be initialised in the current directory, rather than making a new one.
Next go back to your local environment and go into the directory of the repo you want to push to your remote server. Add the remote location, and push:
$ git remote add origin git@[yourserver]:testproject.git $ git status
$ git add . $ git commit -m "initial commit" $ git push origin master
That’s it! I did all of the above following these 2 tutorials:
Note: The above should be carried out by those who are confident at using the command line and is done at your own risk.