If you are a developer and want to have a git server with ability to add users push/pull access you might consider something like a github. But why pay for hosting your private projects if you can use your host in the exactly same way? So let’s try to achieve this on an ubuntu server machine.
After a short search I found gitolite, it looks promising.
Let’s start.
1. Let’s install gitolite
git clone git://github.com/sitaramc/gitolite gitolite-source
cd gitolite-source
sudo mkdir -p /usr/local/share/gitolite/conf /usr/local/share/gitolite/hooks
sudo src/gl-system-install /usr/local/bin /usr/local/share/gitolite/conf /usr/local/share/gitolite/hooks
2. Generate your ssh public key for YOUR machine which you are using to connect to the server. Skip this step in case you already have it. You may use this command with defaults answers and empty passphrase.
3. Copy your LOCAL machine ssh public key to the server. This command will copy the key to your home directory on remote machine.
4. On REMOTE machine copy the key to tmp directory like this
5. Create git user which will host our repos.
6. Login into git user account using password you just gave it
7. Now run the gitolite setup. It will open config file into vi editor allowing you to edit some values before you setup. I left all the values as is and just quit the editor.
8. After setup is completed you have to clone the gitolite-admin repo to your local machine. It will be used for adminstration purposes. The command below depends on your server ssh config. In my case server allows only public key login for certain user. So I had to add git user to AllowUsers line in /etc/ssh/sshd_config.
9. At this point we can start creating repos and adding users. I won’t dive in a lot of detail here, I will just do some basic stuff.
Let’s add a repo. Open conf/gitolite.conf in the gitolite-admin dir you cloned to your local machine. You will see two default repos there, just copy one of them like this:
RW+ = test-user
This will create a repo named test-repo and adds read-write access permissions to user identified by test-user public key.
10. Let’s add that key. Obtain it from the user you wish to give access and and rename it to test-user.pub. Put the key into keydir directory.
11. Let’s commit our changes to the server for them to take effect.
git commit -m "created test-repo, added RW+ to test-server user"
git push origin master
12. Now user can do the following in an existing git repo. 12345 is your ssh custom port.
git push origin master
Now you can simply create new repos and add users to it. Please do read gitolite documentation to discover its power.
That’s it! Goodbye github!
4 Comments
Nice tutorial, and thanks for including the alternate port. For those who never use vi, to quit and save, enter “:q”.
Thanks
.
I’m planning to write a follow-up post adding some web ui for repos. And probably auto deploy through ftp functionality.
But didn’t decide which way to go yet
Hi,
Very useful tutorial, well explained!
BTW, to quit and save VI or VIM, you shoud type “ESC”, to be sure you are exit of the insert mode, and then type “:x”, and not just “:q”, because the “q” is only for quit but not for saving.
Regards!
You could do worse than exporting your tree and then using sitecopy to FTP sync it.
I’ve used sitecopy for a number of years with great success. You can find it at http://www.manyfish.co.uk/sitecopy/
One Trackback/Pingback
[...] Gitosis,在ubuntu上设置http://blog.agdunn.net/?p=277 2. gitolite:在ubuntu上设置http://realcnbs.com/2010/12/setup-git-server-gitolite-ubuntu/ 3. [...]
Post a Comment