Hosting Git Repositories on Ubuntu
|
|
|
Setting up a Git Server on Ubuntu
Github is a wonderful service,site and community of developers. But sometimes you don't want to make your work public. To keep your work private you can pay for private repositories or install your private Git repository on your server.
Gitolite allows you to setup git hosting on a central server, with very fine-grained access control and many (many!) more powerful features.
In this tutorial i will show you detailed instructions of how to setup Git on Ubuntu server
Generate an authentication key for ssh
Open your client machine open a shell prompt and execute the following command to generate an authentication key for ssh :
You should get the below result and input the SSH passphrase. If you keep the original location you should find your newly created ssh key at /Users/<user name>/.ssh/id_rsa
Note: it is possible to just press the enter key when prompted for a passphrase, which will make a key with no passphrase. This is a Bad Idea for an identity key, so don't do it!
Upload your key on your Ubuntu server
We will transfer the key located in the file id_rsa.pub to your Ubuntu host by using scp but you can use ftp,rsync or any other method.
Our ssh key is now present on our Ubuntu server in the following location /tmp/gitolite.pub
Open an ssh session and create a Gitolite user
if your user is named user and our Ubuntu domain is named myubuntu-server.com
We are connected on our Ubuntu server. Let's create a Gitolite user with the useradd command
With the first useradd we create a a new user called gitolite . The -d option is used to set the home directory for the user. The -m option will force useradd to create the home directory.
Additional options :
| useradd command options |
|
|
--system |
Create the user as a system account |
| --shell | The name of user's login shell |
Install Gitolite package
The necessary packages are available in Ubuntu's standard repositories. To install those packages you can type the following shell command :
Execute the Gitolite setup script
Switch to the gitolite user and execute the Gitolite setup command. The setup command called gl-setup expects a pubkey filename the first time it is run and will complain if you don't supply it. It is the ssh key we have created during the first steps.
On subsequent runs it is optional. You need to supply it if you want to change the admin's pubkey without all the steps that gl-admin-push requires and we will not cover.
it creates the following files :
- .gitolite.rc
- conf/gitolite.conf
- keydir/id_rsa.pub
The rest of the process will take place on the client side. Thanks to Git.
Create you own repository
Back on our client machine using our regular account, we can now clone the gitolite-admin repository to adapt the repository configuration to our needs.
So we have a copy of the administration configuration on our client machine. We will go in the gitolite-admin reposiroty and create our repository.
The gitolite-conf should look like
repo gitolite-admin
RW+ = id_rsa
repo testing
RW+ = @all
To create our own repository called devzone. You can add the following snippet
repo devzone
RW+ = @all
To make it available we need to commit and flush
Congratulations you have a new repository called devzone hosted on your Ubuntu server.
If you have any remark or questions feel free to put a comment.
If you enjoyed this tutorial and want to promote it don't hesitate to click on
Sébastien Dante Ursini
Java/Finance Specialist
17 Years of experience in Java
22 Year in Banking/Finance
Based in Geneva/Switzerland