Quick notes for setting up a secure remote Git repository 78

Posted by mikong on August 29, 2008

Toolman Tim wrote a good article about setting up a remote Git repository. It didn’t include the part of creating a git user, so I’ve created my own notes below. His article does offer more explanation on the setup so be sure to check it out.

Prepare the bare Git repo:

$ ssh myserver.com
$ mkdir /var/git
$ mkdir /var/git/myapp.git
$ cd /var/git/myapp.git
$ git --bare init

Create your git user:

$ addgroup git
$ adduser -g git git
$ passwd git
$ chown -R git:git /var/git/myapp.git

Copy your local computer’s public key to the git user’s authorized keys:

$ vi ~/../git/.ssh/authorized_keys

Locate your git-shell:

$ which git-shell

And change your git user’s shell from /bin/bash to the git-shell path:

$ vi /etc/passwd

On your local computer, go to your project directory and point it to the remote server:

$ cd ~/dev/myapp
$ git remote add origin ssh://git@myserver.com/var/git/myapp.git
$ git push origin master

To set the remote repository as the default branch to push and pull to (so you don’t have to specify “origin master” with every push, pull, etc), open your project’s Git config:

$ vi ~/dev/myapp/.git/config

And add the following:

  [branch "master"]
    remote = origin
    merge = refs/heads/master

And that’s all there is to it!