Setting up a central git repository on a server is easy. You basically setup a user, whose home directory is used to store the repositories, and allow access to people using keys, where the user retain their private key and their public key is saved as an authorised key for the git user account.
Note: I've documented the steps I used below for my benefit. The name of the server has been replace with <SERVER>, and the source code repository example is project.git
Set-up
- groupadd git
- useradd -g git -d /home/git -m git
- su - git
- mkdir -p /home/git/.ssh
- cat id_rsa.pub > /home/git/.ssh/authorized_keys
- chmod 600 /home/git/.ssh/authorized_keys
- chmod 700 /home/git/.ssh
- exit
- vi /etc/passwd # change the shell for user git from /bin/bash to /usr/bin/git-shell
- /usr/bin/git-shell
- vi /etc/ssh/sshd_config # ensure that the following are uncommented
- RSAAuthentication yes
- PubkeyAuthentication yes
- AuthorizedKeysFile .ssh/authorized_keys
- service sshd restart
Git Notes
- Create repositories
- cd /home/git
- mkdir project.git
- cd project.git
- git --bare init
- Initially adding to the repository
- git init
- git add .
- git commit -m 'initial commit'
- git remote add origin git@<SERVER>:/home/git/project.git
- git push origin master
- Other users cloning the repository
- git clone git@<SERVER>:/home/git/project.git
- http://git-scm.com/book/en/Git-on-the-Server-Setting-Up-the-Server