Skip to content

Instantly share code, notes, and snippets.

@NetOpWibby
Created January 29, 2020 19:39
Show Gist options
  • Save NetOpWibby/3ac1d0d849a29bd6b4af215a78d317c1 to your computer and use it in GitHub Desktop.
Save NetOpWibby/3ac1d0d849a29bd6b4af215a78d317c1 to your computer and use it in GitHub Desktop.

Setup a simple GIT server for testing on RHEL7

Prepare and setup a simple git server to be used over ssh

  1. Prepare remote server

    # yum -y install git
    # useradd -c "GIT User" -s /usr/bin/git-shell git
    # mkdir ~git/.ssh
    # touch ~git/.ssh/authorized_keys
    # chown git. ~git/.ssh ~git/.ssh/authorized_keys
    # chmod 750 ~git/.ssh
    # chmod 600 ~git/.ssh/authorized_keys
    
  2. Create a priv/pub key pair (if not already)

    # ssh-keygen
    
  3. Add the pub key to the git user's authorized_keys

    # cat id_rsa.pub >> ~git/.ssh/authorized_keys
    
  4. Create new repository on the server

    # sudo -u git bash
    $ cd
    $ mkdir repos
    $ cd repos
    $ git init --bare newrepo.git
    
  5. Clone the repo on the local user and start commiting

    $ git clone [email protected]:repos/newrepo.git
    $ cd newrepo
    $ touch README
    $ git add README
    $ git commit -m "Initial checkin"
    $ git push origin master
    

Setup a Python Simple HTTP server to export the repos via http

  1. Create simeplehttp service unit file

    # cat > /usr/lib/systemd/system/simplehttp.service << EOF
    [Unit]
    Description=Python based SimpleHTTPServer for git repos
    After=network.target
    
    [Service]
    Type=simple
    User=git
    Group=git
    WorkingDirectory=/home/git/repos
    ExecStart=/usr/bin/python -m SimpleHTTPServer 8000
    Restart=on-abort
    
    [Install]
    WantedBy=multi-user.target
    EOF
    
  2. Open firewall and enable+start the service

    # firewall-cmd --add-port 8000/tcp
    # firewall-cmd --add-port 8000/tcp --permanent
    # systemctl daemon-reload
    # systemctl enable simplehttp
    # systemctl start simplehttp
    
  3. Allow the 'dumb' git client to discover repository reference (this should be done for all repos)

    # sudo -u git bash
    $ cd
    $ cd repos/newrepo.git
    $ git update-server-info
    $ mv hooks/post-update.sample hooks/post-update
    
  4. Clone the repo unathenticated via HTTP as:

    $  git clone http://server.example.com:8000/newrepo.git
    

Setup git daemon (optional)

  1. Enable optional repo

    # subscription-manager repos --enable rhel-7-server-optional-rpms
    
  2. Install git-daemon package

    # yum install git-deamon
    
  3. Create git-daemon service unit file (note the --export-all param to export all repos without creating repo.git/git-daemon-export-ok)

    # cat > /usr/lib/systemd/system/git-daemon.service << EOF
    [Unit]
    Description=Start Git Daemon
    
    [Service]
    ExecStart=/usr/bin/git daemon --reuseaddr --export-all --base-path=/home/git/repos/ /home/git/repos/
    
    Restart=always
    RestartSec=500ms
    
    StandardOutput=syslog
    StandardError=syslog
    SyslogIdentifier=git-daemon
    
    User=git
    Group=git
    
    [Install]
    WantedBy=multi-user.target
    EOF
    
  4. Open firewall and enable+start the service

    # firewall-cmd --add-port 9418/tcp
    # firewall-cmd --add-port 9418/tcp --permanent
    # systemctl daemon-reload
    # systemctl enable git-daemon
    # systemctl start git-daemon
    
  5. Clone the repo unathenticated as:

    $  git clone git://server.example.com/newrepo.git
    

See also:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment