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


One thought on “Setting up a FreeBSD multi-user git server”

  1. hi,

    nice quick tutorial and it allowed me to have a git server up and running rather quick.

    But, maybe a note on the use of :
    pw usermod tom -G gitusers

    from the ‘man pw’ :
    -G grouplist Set secondary group memberships for an account. grouplist
    is a comma, space, or tab-separated list of group names or
    group numbers. The user is added to the groups specified
    in grouplist, and removed from all groups not specified.
    The current login session is not affected by group
    membership changes, which only take effect when the user
    reconnects. Note: do not add a user to their primary group
    with grouplist.

    as this command for the user tom, will remove all other groups that tom was part and make him part of the gitusers group.

    Maybe you could add a warning on this. 🙂

    in my case, totally my fault of course as I failed to verify everything, but I ended up removing myself from the wheel group, and creating a bit a panic, some hard work to put me back on.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.