Say you want to manage your own private Git repositories for a Project/Team/Company.
What are your options? GitHub is very convenient, as is Bitbucket , or even your own installation
of GitLab .
But, there is a place for simpler ways to administer your own private Git repositories,
and keep your sources totally under your control. ---You lil' control freak. 😉
First, let's login on the remote machine; the one you want to setup Gitolite on.
Open a terminal and SSH into it:
command
sshgit-server
Then install git:
command
sudoaptinstallgit
Now, add the user that will be in charge of managing the repos and enforce the access
control rules, then disable its password access for security reasons:
command
sudoaddusergit
sudopasswd-lgit
On your local machine, open a new terminal and copy your public key to the remote machine:
command
scp~/.ssh/id_rsa.pubgit-server:
If successfully, you'll have the id_rsa.pub file available on the remote machine in the
$HOME directory for the remote yolo user.
It's time to create the $HOME directory for the git user; then we'll move the
id_rsa.pub file to /home/git/.ssh/yolo.pub and adjust some permissions and directory ownership:
command
sudomkdir-p/home/git/.ssh
sudomv~/id_rsa.pub/home/git/.ssh/yolo.pub
sudochmod700/home/git/.ssh
sudochown-Rgit:git/home/git/
Let's impersonate the git user, then clone and install Gitolite:
Exit the git user shell and re-login to make the commands we just installed in
~/bin available to us.
Then setup Gitolite with yolo.pub as the admin key:
command
exit
sudosugit-l
gitolitesetup-pk~/.ssh/yolo.pub
exit
exit
Exit the remote machine ---you'll need to type exit twice, because you are two levels deep (yolo => git).
DEBIAN NOTE
If the scripts in ~/bin aren't picked up automatically,
you might need to create a ~/.bash_profile file and modify the $PATH
by appending ~/bin to it like this:
Get the public keys from users that want Git access and put them in ~/gitolite-admin/keydir.
Name them accordingly (e.g. tom.pub and jerry.pub) since those names are the ones you
are going to use to configure user access control.
To create a new repository called yolo-project, give yourself permission to do
anything, then give read-write access to tom and jerry, open the
~/gitolite-admin/conf/gitolite.conf file and put these lines in:
~/gitolite-admin/conf/gitolite.conf
repo yolo-project
RW+ = yolo
RW = tom jerry
After that you'll need to commit and push those changes to the remote gitolite-admin repo:
command
cd~/gitolite-admin
gitadd.
gitcommit-m"Add new repo, add new keys, give access"
gitpush
That's it, Gitolite will take care of creating the new repository, then gate access to it
according to your specified rules.