Hash: SHA256

Stuff you need to know

As I was putting this very website online this day, I felt that all the modifications that I did needed to be tracked via a version control system. As git is the most popular and efficient version control system, and as setuping gitosis server is one of the things I usually do at work for guys at EuroDNS, it’s pretty obvious for me that I needed to document somehow this tiny procedure and stop searching google each time I need to do it.


As often here, I will use a brand new Centos6.2 installation with EPEL repository configured for this demonstration, where I have root credentials (needed). You will need your firewall to authorize incoming connections to port 22.


Fire yum, and you’re good. It will install gitosis, the dependencies and create the required user on the system.

# Install the stuff
yum install gitosis
=>	...
	Running Transaction
	  Installing : 1:perl-Error-0.17015-4.el6.noarch	1/6 
	  Installing : python-setuptools-0.6.10-3.el6.noarch	2/6 
	  Installing : rsync-3.0.6-5.el6_0.1.x86_64	3/6 
	  Installing : perl-Git-1.7.1-2.el6_0.1.noarch	4/6 
	  Installing : git-1.7.1-2.el6_0.1.x86_64	5/6 
	  Installing : gitosis-0.2-9.20080825git.el6.noarch	6/6 

	  gitosis.noarch 0:0.2-9.20080825git.el6

	Dependency Installed:
	  git.x86_64 0:1.7.1-2.el6_0.1	perl-Error.noarch 1:0.17015-4.el6	perl-Git.noarch 0:1.7.1-2.el6_0.1	python-setuptools.noarch 0:0.6.10-3.el6	rsync.x86_64 0:3.0.6-5.el6_0.1                    

# Check that the user has been correctly installed
grep git /etc/passwd
=>	gitosis:x:497:496:git repository hosting:/var/lib/gitosis:/bin/sh

Configuring gitosis-admin

Gitosis manages git repo access, and its configuration is in a repository in itself. We will then, as root, create ssh keys and initialise the repository using our SSH public key.

# Create private/public SSH key pair
ssh-keygen -t rsa
=>	Generating public/private rsa key pair.
	Enter file in which to save the key (/root/.ssh/id_rsa): 
	Created directory '/root/.ssh'.
	Enter passphrase (empty for no passphrase): 
	Enter same passphrase again: 
	Your identification has been saved in /root/.ssh/id_rsa.
	Your public key has been saved in /root/.ssh/id_rsa.pub.
	The key fingerprint is:
	b6:42:5f:b2:c0:82:c2:88:23:24:b5:24:c9:e3:51:94 root@myserver
# Initialise gitosis-admin repository specifying the newly created SSH key (as user gitosis)
sudo -H -u gitosis gitosis-init < ~/.ssh/id_rsa.pub 
=>	Initialized empty Git repository in /var/lib/gitosis/repositories/gitosis-admin.git/
	Reinitialized existing Git repository in /var/lib/gitosis/repositories/gitosis-admin.git/

We see that gitosis created a new empty directory in the gitosis user home directory. As we are granted to do so by having imported our SSH key, let’s clone the gitosis-admin repository:

git clone gitosis@localhost:gitosis-admin.git
=>	Initialized empty Git repository in /root/gitosis-admin/.git/
	remote: Counting objects: 5, done.
	remote: Compressing objects: 100% (5/5), done.
	remote: Total 5 (delta 0), reused 5 (delta 0)
	Receiving objects: 100% (5/5), done.
cd gitosis-admin/
# So, what's in there ?
=>	gitosis.conf	keydir
# Let's display what's in gitosis.conf
cat gitosis.conf 

	[group gitosis-admin]
	writable = gitosis-admin
	members = root@myserver
If you want to add a user (from any host) in gitosis, you need to create a file in the keydir folder containing the public SSH key of the user, and naming the file using the convention user.pub. The user is the recognized in the gitosis.conf file.
# Step into the recently cloned repo
cd gitosis-admin
# Create the user ssh public key file
cat > keydir/ben.pub
	ssh-rsa AAAAB...Q== Mac Pro Home

Now, add the user ben to the gitosis-admin group in the gitosis.conf file :


[group gitosis-admin]
writable = gitosis-admin
members = root@myserver ben

We still need to apply modifications:

# Adding the configuration file to source version manager
git add keydir/legeek.pub
# Commiting to the locally cloned repository the modifications we've done :
git commit -a -m "adding ben to gitosis-admin, and key"
=>	[master 0ce1899] adding ben to gitosis-admin, and key
	 Committer: root 
	 2 files changed, 2 insertions(+), 1 deletions(-)
	 create mode 100644 keydir/ben.pub
# Push modifications to the original repository
git push
	Counting objects: 8, done.
	Delta compression using up to 2 threads.
	Compressing objects: 100% (5/5), done.
	Writing objects: 100% (5/5), 1.50 KiB, done.
	Total 5 (delta 1), reused 0 (delta 0)
	To gitosis@localhost:gitosis-admin.git
	   ada0e7f..0ce1899  master -> master

I’m now able to connect to gitosis using my remote computer and clone the gitosis-admin repo:

git clone gitosis@myserver:gitosis-admin.git
=>	Cloning into gitosis-admin...
	Host key fingerprint is 69:eb:4c:11:d6:a4:fb:cf:26:cd:1a:eb:41:0f:60:3c
	+--[ RSA 2048]----+
	|          .      |
	|       . +       |
	|        E .      |
	|       o *       |
	|        S o      |
	|       . = o     |
	|        o +o.    |
	|       +  .*+    |
	|        o.++o    |

	remote: Counting objects: 10, done.
	remote: Compressing objects: 100% (10/10), done.
	remote: Total 10 (delta 1), reused 4 (delta 0)
	Receiving objects: 100% (10/10), done.
	Resolving deltas: 100% (1/1), done.

Adding a new repo

Now, add write right on a repo called bkraft to the gitosis-admin group on our local computer, commit and push the modifications to the remote repo. So, here is the gitosis.conf

# Content of the file
cat gitosis.conf
=>	[gitosis]

	[group gitosis-admin]
	writable = gitosis-admin bkraft
	members = root@myserver legeek
# commit des modifications
git commit -a -m "Adding write rights on bkraft repo"
=>	[master e3f7d83] Adding write rights on bkraft repo
 	Committer: Benjamin KRAFT 
 	1 files changed, 1 insertions(+), 2 deletions(-)
# push the modification remotely
git push
=>	Host key fingerprint is 69:eb:4c:11:d6:a4:fb:cf:26:cd:1a:eb:41:0f:60:3c
	+--[ RSA 2048]----+
	|          .      |
	|       . +       |
	|        E .      |
	|       o *       |
	|        S o      |
	|       . = o     |
	|        o +o.    |
	|       +  .*+    |
	|        o.++o    |

	Counting objects: 5, done.
	Delta compression using up to 8 threads.
	Compressing objects: 100% (3/3), done.
	Writing objects: 100% (3/3), 399 bytes, done.
	Total 3 (delta 0), reused 0 (delta 0)
	To gitosis@pontos.dotnul.org:gitosis-admin.git
	   0ce1899..e3f7d83  master -> master

Initial importation

Now that we have the rights of writing into a repository, we’ll import the content of a folder, called tutorial were we have files into the previously named repo.

# Go to the folder
cd tutorial
# Initialize git in this repository
git init
=>	Initialized empty Git repository in /Users/benjaminkraft/pouet/.git/
# ignore Mac OS created files and this very file 
cat > .gitignore
# Add all files to git source management
git add -A
# Commit everything
git commit -a -m "original import"
=>	Committer: Benjamin KRAFT 
	88 files changed, 39883 insertions(+), 0 deletions(-)
	create mode 100644 Rakefile
	create mode 100644 Rules
	create mode 100644 config.yaml
# Add a connection to the remote end repository
git remote add origin gitosis@myserver:bkraft.git
# Push locally committed files to the remote repository
git push origin master
=>	Host key fingerprint is 69:eb:4c:11:d6:a4:fb:cf:26:cd:1a:eb:41:0f:60:3c
	+--[ RSA 2048]----+
	|          .      |
	|       . +       |
	|        E .      |
	|       o *       |
	|        S o      |
	|       . = o     |
	|        o +o.    |
	|       +  .*+    |
	|        o.++o    |

	Counting objects: 74, done.
	Delta compression using up to 8 threads.
	Compressing objects: 100% (69/69), done.
	Writing objects: 100% (74/74), 643.30 KiB, done.
	Total 74 (delta 7), reused 0 (delta 0)
	To gitosis@pontos.dotnul.org:bkraft.git
	 * [new branch]      master -> master

Congrats, your files are now stored on the remote repo !

Comment: GPGTools - http://gpgtools.org


Hint: To validate signature, please view page source and copy html code between BEGIN PGP Signed message and END PGP Signature anchors.

Created the 2012-01-21

Share this

Article content


10 last blog posts

Related to this article

blog comments powered by Disqus