How to configure gitolite on the Cubieboard running Cubian

In my previous post I outlined the steps I took to install git and gitolite on the Cubieboard, on top of Cubian X. In this guide I’ll show you what I did to:

  • add a new user to my git server
  • create a new empty repository
  • import my existing repositories from my old Digital Ocean server
  • import my GitHub repositories

How to add a new user to gitolite

  1. First, clone the gitolite-admin repository on your local machine, if you haven’t done so already:
    git clone git@192.168.0.101:/gitolite-admin gitolite-admin-cubie
  2. Inside the gitolite-admin-cubie directory you should have two directories: conf and keys. To add a new user, you basically need to add her key to the keys directory. Note that you can create subdirectories under keys. Let’s assume you want to add a new user, and you have the public key: mary.pub. Note that you will use the corresponding private key to authenticate to git.
    • Copy the two public key to the key folder.
    • Add the key, commit the changes and push to the server:
      git add keys/mary.pub
      git commit -m Add Mary's keys.
      git push origin master
      

Now, user Mary should be able to access the git server using her private key.

How to create a new empty repository and give rights to it

  1. Edit conf/gitolite.conf:
    nano conf/gitolite.conf

    Initial file looks something like this:

    repo    gitolite-admin
            RW+     =   john
    
    repo    testing
            RW+     =   @all
    

    To add a new repository “myapp” and give user Mary full access to it, change it to:

    repo    gitolite-admin
            RW+     =   john
    
    repo    testing
            RW+     =   @all
    
    repo    myapp
            RW+     =   mary
    

    If you want user John to have access too, do something like:

    repo    gitolite-admin
            RW+     =   john
    
    repo    testing
            RW+     =   @all
    
    repo    myapp
            RW+     =   mary john
    

    You can read a lot more about the gitolite configuration file here.

  2. Add, commit, and push the changes:
    git add conf/gitolite.conf
    git commit -m "Add new myapp repo."
    git push origin master
    

Now Mary can do something like:

git clone git@192.168.0.101:/myapp

to clone the new empty repository.

How to import repositories from another server

  1. First, on your local machine, change the gitolite.conf file to add a new empty repository. You will import your existing repository into this new empty one.
    repo    gitolite-admin
            RW+     =   john
    
    repo    testing
            RW+     =   @all
    
    repo    myapp
            RW+     =   mary john
    
    repo    awesome-app
            RW+     =   john
    
  2. Add, commit, and push the changes:
    git add conf/gitolite.conf
    git commit -m "Add awesome-app repo."
    git push origin master
    
  3. On your Cubieboard, change to user git, change to the repositories folder and you should see the new empty repository awesome-app.git:
    sudo su git
    cd /home/git/repositories
    ls -la
    
  4. Change to the awesome-app.git directory and import your code from your remote server:
    cd awesome-app.git
    git --bare fetch git@existing-server.com:/awesome-app.git master:master
    

    This assumes you already have access to your existing git server from the Cubieboard. To set that up you basically need your private key for your existing git server in /home/git/.ssh and you need to edit your /home/git/.ssh/config file adding the following lines:

    Host existing-server.com
        Hostname existing-server.com
        User git
        IdentityFile /home/git/.ssh/existing-server-key
        ServerAliveInterval 300
    
  5. On your local machine you can now clone your imported repository, from your Cubieboard:
    git clone git@192.168.0.101:/awesome-app

Importing GitHub repositories

Importing your GitHub repositories is similar to importing repositories from your existing server. You just need to:

  1. Make sure you configure GitHub access on your Cubieboard, under user git.
  2. On your local machine, add a new empty repository by editing gitolite.conf and pushing the changes to the Cubieboard server.
  3. On your Cubieboard, switch to user git, change to the new empty repository and do something like:
    git --bare fetch https://username@github.com/username/repository.git master:master

If you have any questions, feel free to use the comments form below.

How to install git and gitolite on the Cubieboard with Cubian

I’ve been using a Digital Ocean droplet to run git, gitolite and GitList, to host my private git repos for some time, but I recently decided to switch to a Cubieboard, because it’s more fun and an easy way to save about $10/mo. In this post I’ll show you the steps I took to install git and gitolite on the Cubieboard, using Cubian X.

  1. Install git and gitolite:
    sudo apt-get install git gitolite
  2. Add an user to handle gitolite:
    sudo adduser --system --shell /bin/bash --group --disabled-password --home /home/git git

    The code above creates the git user, without password, so direct logins are not possible.

  3. Switch to the git user:
    sudo su git
  4. Change directory:
    cd /home/git
  5. Generate a RSA key:
    ssh-keygen -t rsa

    You can safely accept the defaults. You should get something like this:

    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/git/.ssh/id_rsa): 
    Created directory '/home/git/.ssh'.
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /home/git/.ssh/id_rsa.
    Your public key has been saved in /home/git/.ssh/id_rsa.pub.
    The key fingerprint is:
    4c:44:82:2e:ad:86:4e:9a:83:ef:e9:97:84:46:2d:d9 git@cubie
    The key's randomart image is:
    +--[ RSA 2048]----+
    |         +o      |
    |        oo*      |
    |   + o o.o       |
    |  + F o.o        |
    | . + o *S        |
    |  + . .. .       |
    | o o .  .        |
    |  o o            |
    | ...             |
    +-----------------+
    
  6. Still as the git user configure gitolite:
    gl-setup /home/git/.ssh/id_rsa.pub

    You should get the following output:

    The default settings in the rc file (/home/git/.gitolite.rc) are fine for most
    people but if you wish to make any changes, you can do so now.
    
    hit enter...

    Press the Enter key on your keyboard then you can just save the file and exit. If you’re using nano, just press CTRL+O and then CTRL+X.

  7. Copy the id_rsa (not the id_rsa.pub) file from /home/git/.ssh to your local computer.
  8. Configure SSH access to your Cubieboard for the git user. On a Mac you would place your id_rsa file (you can rename it) in your home folder, under .ssh, and you would edit the config file under .ssh by adding something like this:
    Host 192.168.0.101
        Hostname 192.168.0.101
        User git
        Port 36000
        IdentityFile /Users/your-username/.ssh/cubie_id_rsa
        ServerAliveInterval 300
    

    Now, if you do ssh git@192.168.0.101 you should get something like:

    hello id_rsa, this is gitolite 2.3-1 (Debian) running on git 1.7.10.4
    the gitolite config gives you the following access:
         R   W 	gitolite-admin
        @R_ @W_	testing
    Connection to 192.168.0.101 closed.
  9. You can now clone the gitolite-admin repository (which is used to change the gitolite configuration) from your Cubieboard to your local computer:
    git clone git@192.168.0.101:gitolite-admin.git
    1. git and gitolite installation is now complete. In my next post I’ll show you how to actually configure gitolite, how to add new users and new repositories.

Cubian X – How to move filesystem to HDD

If you want to boot Cubian from a hard drive instead of the SD card or the nand flash, you can attach the hard disk to your Cubieboard via USB or via the SATA connector. I connected mine via USB, using a powered USB hub, since I noticed the Cubieboard didn’t provide enough power for the hard drive, when connected directly.

The tutorial is focused on Cubian X, but with minor changes should work for other distributions as well.

  1. Get the path to your hard disk (should be something like /dev/sda1):
    sudo fdisk -l [enter]
  2. Create a primary partition on your hard drive. Be aware that all the information on your hard drive will be lost!:
    sudo fdisk /dev/sda[enter]

    Replace /dev/sda with the path you got in step 1.
    To create the partition you should issue the following commands:

    Command (m for help): n [enter]
    Partition type:
    p primary (0 primary, 0 extended, 4 free)
    e extended
    Select (default p): p [enter]
    Partition number (1-4, default 1): [enter]
    Using default value 1
    First sector (2048-524288000, default 2048): [enter]
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-524288000, default 524288000): [enter]
    Using default value 524288000
    

    Note that if you have any existing partitions you need to remove them first, so your outout may vary slightly. You can always type m [enter] for help.

  3. Create a filesystem on your newly created partition:
    sudo mkfs.ext4 /dev/sda1 [enter]

    Again, I’m assuming your partition is /dev/sda1, but make sure to adjust your commands if your setup is different.

  4. Move rootfs to the hard drive:
    sudo dd if=/dev/nandb of=/dev/sda1 bs=1M [enter]
    sudo sync [enter]

    Here I’m moving rootfs from the nand to the hard drive, as I previously installed Cubian on the nand via cubian-nandinstall. To move it from the SD-card, you should probably use:

    sudo dd if=/dev/mmcblk0p2 of=/dev/sda1 bs=1M [enter]
    sudo sync [enter]

    This might take a while, be patient.

  5. Edit uEnv.txt:
    sudo nano /boot/uEnv.txt [enter]

    Replace this line:

    root=/dev/nandb rootwait

    or this one (if you move the filesystem from the SD card):

    root=/dev/mmcblk0p2 rootwait

    with:

    root=/dev/sda1 rootwait
  6. Reboot your system:
    sudo reboot [enter]

    Cubian should now boot from the hard drive. Give it some time.

  7. Resize the filesystem to fully use your hard drive space:
    sudo resize2fs /dev/sda1 [enter]
  8. Edit /etc/fstab:
    sudo nano /etc/fstab [enter]

    and replace this line:

    /dev/mmcblk0p2 / ext4 defaults 0 1

    or this line:

    /dev/nandb / ext4 defaults 0 1

    with:

    /dev/sda1 / ext4 defaults 0 1

That’s all!