User Tools

Site Tools


computing:gitserver

  • gitserver
  • Jonathan Haack
  • Haack's Networking
  • netcmnd@jonathanhaack.com

Configure the machine that will be running the git server first. In order, this requires creating the git user, and then creating the .ssh directory and authorized keys files, and then establishing appropriate permissions.

sudo adduser git
su - git
cd ~
mkdir .ssh && chmod 700 .ssh
touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys

You can add keys to authorized keys file using copy and paste, or using some bash syntax (from within the git user's shell) as follows:

cat /tmp/id_rsa.john.pub >> ~/.ssh/authorized_keys

Now, let's finish configuring the server.

cd /srv
mkdir git
cd git/
mkdir repositoryname.git
cd repositoryname.git/
git init --bare --shared

The shared option above allows more than just the git user to write to the repository. The users must have permissions to do so, however, so since the directories were created by the git user, one can add the user to the git group. If you need this functionality, then on the server, make sure to execute the following command for each user:

sudo adduser <username> git

The instructions below assume the clients are on the same LAN and using a directory in their home directory dedicated to git repos. If the clients are not on the same LAN, then use openvpn to tunnel into the LAN.

cd ~
mkdir git
cd git/
git clone git@gitserver:/srv/git/repositoryname.git
git clone git@gitserver:/media/sexa/Stores/Zion/zion.git
cd repositoryname/
nano README
git commit -am"added a line to README for repository participants"
git push origin master

This method has everyone using the user git in order to clone the repository, and unless tweaked will allow users shell access to the server. To stop shell access, simply add :/bin/false to the end of the git user's entry in /etc/passwd. Using other user names for access / cloning will be covered in a later tutorial. Set the new origin as master:

git remote set-url origin ssh://user@10.28.88.2:/srv/lion.git
git remote set-url origin ssh://user@10.28.88.2:/media/user/Store/Lion/lion.git
git remote set-url origin ssh://user@10.28.88.2:46787/media/user/Store/Lion/lion.git
git remote set-url origin ssh://user@10.28.28.2:/home/Lion/lion.git

Of course, to clone the repository:

git clone ssh://user@10.28.88.2:46787/media/users/Store/Lion/lion.git

The restricted shell for git user may need to be restored to normal log in shell for certain repository servers.

git:x:1001:1001:,,,:/var/opt/gitlab:/bin/sh

Accessing the new server … first, create your public/private keypair first …

cd ~
ssh-keygen
cat ~/.ssh/id_rs.pub

Then, ssh into your vps and/or simply do this on your localhost and clone the repo and make your first commit. You can also do this with the Haacking Club repo.

cd ~
mkdir git
cd git/
git clone git@hc.jonathanhaack.com:oemb1905/haackingclub.git
cd haackingclub
touch yourname.notes
nano yourname.notes
git add yourname.notes
git commit -am"added my notes file and put my project description in it"
git pull
git push

File and directory permission recommendations for git repository contents:

find .git -type d | xargs chmod 755
find .git/objects -type f | xargs chmod 444
find .git -type f | grep -v /objects/ | xargs chmod 644

Set the default editor

git config --global core.editor "nano"

This tutorial is a designated “Invariant Section” of the “Technotronic” section of Haack's Wiki as described on the Start Page.

oemb1905 2019/11/09 16:00

computing/gitserver.txt · Last modified: 2019/11/09 23:08 by oemb1905