Setting up a FreeBSD multi-user git server

This is a quick note on how to create a multi-user git server hosted on your own FreeBSD set-up, using the SSH protocol for reading/writing from/to repositories. Steps to follow (as 'root'):

  1. Install the 'git' package:
    pkg_add -r git
  2. Create a group called 'gitusers':
    pw groupadd gitusers
  3. Create a user called 'gitserver', part of the 'gitusers' group, without shell access:
    pw useradd gitserver -g gitusers -s /sbin/nologin -m
  4. Invite existing users to the 'gitusers' group, (e.g.: users 'tom' and 'alice'):
    pw usermod tom -G gitusers
    pw usermod alice -G gitusers
  5. Create a new example repository, in `/home/gitserver/', called 'example-repository':
    # Create an empty repository:
    cd /home/gitserver/
    mkdir example-repository
    cd example-repository
    git init
    # Clone into a bare repository:
    cd ..
    git clone --bare example-repository example-repository.git
  6. Change permissions, to allow 'gitusers' group members to execute and read/write from/to repository contents:
    cd /home/gitserver/
    chown -R gitserver:gitusers ./example-repository.git/
    chmod -R g=rxw ./example-repository.git
  7. Clone the repository on the client machine, and add your first commit to the 'master' branch: NOTE: Replace hostname.tld, with the hostname of your machine.
    # Clone the repository:
    git clone ssh://tom@hostname.tld/home/gitserver/example-repository.git
    # Add your first commit:
    cd example-repository.git
    touch README
    git add README
    git commit -am "First commit."
    # Push changes
    git push origin master


Leave a Reply

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