How to setup a shared GIT repository using SSH

edited September 2014 in Proposed How-Tos
First, we start off with any server from Vultr. Once you have it setup to your liking, we create a GIT user, it can be named anything you want, but for simplicity, we'll use "git".

Start by adding the user:

adduser git

Then, become the git user via:

su - git

Then, we change to our $HOME directory, and create SSH credentials:

cd /home/git
ssh-keygen -t rsa -b 4096 -N ''

This will create not only our own public key, but also the ~/.ssh directory with the correct permissions

Now, you will want to create a file with a list of authorized keys so that your team can push code:

touch ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

Now, edit the file you just created, and paste your OpenSSH formatted public keys inside.

Save the file and close, and you should be returned to the git user shell.

Once you have done that, now create a project:

mkdir ~/project.git
cd ~/project.git
git init --bare

Now, install your GIT package from your OS's repositories:

(Debian) apt-get install git
(CentOS) yum -y install git

This will install 'git-shell', which can be used to allow only GIT access to your 'git' account. Set it as the shell to your git account by executing:

chsh -s /usr/bin/git-shell git

On your machine with the corresponding private key, execute a clone from:

git@server.hostname:project.git

You can now pull and push to your heart's content, and setup hooks in /home/git/project.git/hooks/

Sign In or Register to comment.