May 282012
 

Before You Start

  • Since the gitolite administration is done remotely, you’ll need to have git installed on your local machine.  github has an excellent guide to help you set up git.  If this is your first delve into the git world, surf over to the official page and read through some of the excellent documentation.  It’s important to understand how to use git before you attempt to install gitolite, since its installation involves using git commands.
  • If you follow this guide 100%, your local workstation will need to have ssh and scp installed on it
  • This may go without saying, but you’ll also need a basic understanding of using vim to open, edit, and save files on the Diskstation.  If you’re new to vim, check out A Byte of Vim.
  • The steps outlined here assume a Linux or Mac workstation.  Your mileage may vary with other operating systems when steps on the local workstation are necessary.
  • This will take some time.  Do not start this if you have something important to do soon.

Conventions

  • Any command beginning with “DiskStation> ” is to be run on the Synology DiskStation
  • Any command beginning with “localhost$ ” is to be run on your local workstation

Bootstrap and Install Git on your Diskstation

  1. Find what CPU type is in your Synology NAS server
  2. Enable ssh terminal access in your Synology control panel using the “Terminal” icon
  3. Reboot your Diskstation
  4. Login to your Diskstation as root using SSH.  Enter your Diskstation’s admin password when prompted for a password.
  5. Change to the @tmp directory
  6. Download the bootstrap file to for your CPU type using wget.  The example below is for the DS212J with the Marvel Kirkwood mv6281 ARM processor.  Use the Overview on modifying the Synology Server page to identify the correct bootstrap file URL to use when executing the wget command below.
  7. Change the bootstrap file permission so it is executable
  8. Execute the bootstrap file
  9. Delete the bootstrap file
  10. Edit the root user .profile file and comment out PATH and its export
  11. Comment out the .profile PATH and export, and save (escape+ZZ)  (Why you may ask?)
  12. Reboot your Diskstation
  13. Login to your Diskstation as root using SSH
  14. Update the ipkg list
  15. Install coreutils
  16. And the moment we’ve been waiting for…  Install git
  17. Make symlinks to the git binaries in /usr/bin

At this point, your Synology server has the core required software installed.  From here on, it’s configuration and a bit of SSH fun to get gitolite up and running.  Let’s get the SSH bit out of the way, shall we?

Install SCP (optional)

By default, DSM 4.0 Diskstations do not have SCP installed.  Though this is somewhat optional, I find it to be the easiest way to copy and manage the public keys we’ll be working with in later steps.  If you do not use this method, you could always copy your keys over to the Diskstation volume using any normal method, such as AFP, NFS, FTP, whatever floats your boat.

  1. On your Diskstation, change to the /volume1/@tmp directory
  2. Download the OpenSSH ipkg
  3. Inflate the ipkg
  4. Inflate the data.tar.gz file
  5. Copy the scp binary to /bin
  6. Delete the OpenSSH files from /volume1/@tmp

SCP is now installed, give it a try on the command line!

Got that out of the way, now let’s move on to some easier user management stuff.

Create a Git user on the Diskstation

You’ll need one for gitolite to use, often referred to as a “hosted user.”  Fortunately, you can just create a new user using the Diskstation’s Web Desktop.

  1. Login to the Diskstation Web Desktop as the admin user
  2. Launch the Control Panel from the Web Desktop
  3. Launch Users from within the Control Panel
  4. Click Create User
  5. Enter the following details and a password and click Next
    Username: git
    Description: Git hosting user
  6. On the User Groups tab, ensure only “users” system default group is checked, then click Next
  7. Assign privileges – shared folders: It is a good idea to limit the access of this user, so select the No Access checkboxes for all your shares and click Next
  8. Don’t worry about a quota, unless you really need to and click Next
  9. Assign privileges – applications: uncheck the grant checkbox for all applications and click Next
  10. Review the account details and click Apply when to create the git user
Now, back to the command line!  Does it feel like home?

Enable Shell Access for the Git User

  1. Login to your Diskstation as root using SSH.  Enter your Diskstation’s admin password when prompted for a password
  2. Edit the /etc/passwd file
  3. Find the git user entry and change the shell from /sbin/nologin to /bin/ash and save (escape+ZZ)

Generate a Key Pair on your Local Workstation

If you already have a key pair generated that is NOT already used for key authentication as the git hosting user, you can skip this step.

Important: These steps are performed on your local workstation, NOT the Diskstation!

Note: If you already have key pair authentication to the DiskStation setup for the git hosting user, you’ll need to generate two key pairs, one for the gitolite admin and one for normal use.  You’ll also have to configure SSH host aliases to send the right key. 

  1. Generate a RSA public/private key pair – leave the passphrase empty and use default location and name
  2. SCP the public key to the Diskstation

Cool.  The public key is on the DiskStation and in the git user’s home directory.  But there’s more to do…

Configure the Git Hosting User’s Profile and Home Directory

  1. Login to the DiskStation as the git user
  2. Switch to the git hosting user using su
  3. Create a new .profile for the git user
  4. Make the contents of the .profile look similar to below and save (escape+ZZ), changing the value of HOME if you have more than one volume or a volume not named volume1
  5. Source the new .profile so environment variables take effect
  6. Make a bin directory in the git hosting user home directory

There’s a light at the end of the tunnel… Is that a train?

Install Gitolite on the DiskStation and Run Setup

Don’t install gitolite as root.  If you followed the above instructions correctly, you should have no issue installing as a git hosting user!

  1. Make sure you’re the git user!
  2. As the git user, download gitolite by cloning the github repository
  3. As the git user, run the gitolite install command
  4. Setup gitolite using the public key you uploaded many steps ago, located in the git hosting user home directory (it is safe to ignore the WARNINGS you see below – others, maybe not)

Hey!  Good work!  Gitolite is now installed on your DiskStation!  Why not take it for a spin?  In fact, it is mandatory to create users and repositories.

Clone the Admin Repo

Important: These steps are performed on your local workstation, NOT the Diskstation!

  1. Clone the admin repository to a writeable directory on your workstation

Take a break, then go forth and administer your gitolite installation!

Changelog

05/28/2012 – Initial publication
05/31/2012 – Corrected typo on gitolite install command
01/31/2013 – Added link explaining why commenting out root path is necessary

 

  50 Responses to “Comprehensive Guide to Git and Gitolite on a Synology DiskStation with DSM 4.0”

  1. At “DiskStation> git clone git://github.com/sitaramc/gitolite”, I get the error message “-ash: git: not found”. Looking closer, I can see that I don’t have access to neither the git command nor the ipkg command as user=git.. I have them as root though.

    I was so close. please help me, Ryan:(

    • More info:
      the profile for git is exactly the same as yours.
      in /etc/passwd, I have:
      “git:x:1029:100:Git hosting user:/var/services/homes/git:/bin/ash”, only changing the last part “bin/ash”

    • Hi Sebastian,

      It sounds like the PATH for the git user isn’t setup correctly.

      Easy way to check:

      DiskStation> su – git # become git user and take on the git user’s user environment
      DiskStation> env # print out env variables

      You should see something like:

      USER=git
      HOME=/volume1/homes/git
      PAGER=more
      LOGNAME=git
      TERM=xterm-256color
      PATH=bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin:/usr/local/sbin:/usr/local/bin
      SHELL=/bin/ash
      PWD=/volume1/homes/git
      PGDATA=/var/service/pgsql

      If you don’t, make sure you didn’t miss any steps in the section “Configure the Git Hosting User’s Profile and Home Directory”. The important piece here is that the git user’s .profile file in that user’s home directory e.g. (/volume1/homes/git) has a PATH variable defined and exported. See that section of the post for the exact contents needed.

      Let me know how it goes!

      • I have it the same as you, only difference is I have “TERM=XTERM” (without -256color). Path is identical.

        /volume1/homes/git only has “Sebastian.pub” and folder “bin”, which is empty.

        • As root, try:

          DiskStation> su – git
          DiskStation> whoami
          git
          DiskStation> which git
          /usr/bin/git

          If /usr/bin/git doesn’t show up, make sure you made your symlinks as the root user

          (as root)
          DiskStation> ln -s /opt/bin/git* /usr/bin

          • SUCCESS! Wow, so fast feedback. Karma to you:)

          • Hi Ryan,

            Thank’s for a great tutorial.

            I’m stuck at this point as well.

            I’ve commented out the PATH in the root .profile, created teh symlinks (as root) and creted the .profile for the git user.

            However, when I type which git, the system points to /opt/bin/git

            typing env, shows that PATH is prepended with /opt/bin:/opt/sbin: for both root and git users.

            Any help appreciated – Magnus

          • Please disregard from my previous question.

            Solved it, error when copy-pasting the PATH from your webpage.

            Sorry :)

          • Glad you’ve got everything in working order! Thanks for the kudos!

  2. I got an error when I install the Gitolite.
    When I do this “DiskStation> gitolite setup -pk $HOME/yourname.pub”
    I got the error “gitolite: not found”

    • If you followed the instruction to a tee, gitolite should have been linked in your $HOME/bin directory. This should also be part of the git hosting user’s path in that user’s .profile. The fact that it isn’t means you likely missed a step or two.

  3. I succeed to install gitolite. Thank you for your tutorial.
    Just last one question : It exist a client for desktop or a web application to manage the git server like GitHub. I heard gitweb, but does exist it other ?

    • Github is closed source software, but there are other alternatives out there. Don’t expect them to be as robust and elegant. Gitweb is one option, but Gitlab is also worth a try if you don’t mind running Ruby on Rails.

  4. Question about step 11: Uncomment after installation? Seems weird to leave root’s path unset.

  5. This is a great post!

    When I type the following command,

    1. localhost$ scp id_rsa.pub git@diskstation:yourname.pub
    2. git@diskstation’s password:
    id_rsa.pub

    I only got “Permission denied, please try again”.

    I wondering know that does “yourname.pub” means that I should replace the “youranme” with current user name on the localhost?

    • As a rule of thumb, you usually name the public key after the username of the git user you’re going to configure in the repository. In this case, replace “yourname” with that name. Also be sure you are substituting the correct values in there for the git user’s password, and the proper IP or hostname for your Disk Station.

  6. Hi,

    First thank you on very good step by step tutorial, i follow and all works like charm but only on localhost.
    Did you try make it work from remote computer ? I have problem, when i want to clone i must use git clone ssh://user@publicip/~user/repositories/repo.git and this work, but when i want to push then i got error:

    Counting objects: 7, done.
    Delta compression using up to 2 threads.
    Compressing objects: 100% (3/3), done.
    Writing objects: 100% (4/4), 394 bytes, done.
    Total 4 (delta 1), reused 0 (delta 0)
    remote: Empty compile time value given to use lib at hooks/update line 6
    remote: Use of uninitialized value in require at hooks/update line 7.
    remote: Use of uninitialized value in require at hooks/update line 7.
    remote: Can’t locate Gitolite/Hooks/Update.pm in @INC (@INC contains: /usr/lib/
    perl5/5.8.6/MARVELL_88F6281 /usr/lib/perl5/5.8.6 /usr/lib/perl5/site_perl/5.8.6/
    MARVELL_88F6281 /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl .) at ho
    oks/update line 7.
    remote: BEGIN failed–compilation aborted at hooks/update line 7.
    remote: error: hook declined to update refs/heads/master
    To ssh://user@pubip/~user/repositories/gitolite-admin.git
    ! [remote rejected] master -> master (hook declined)
    error: failed to push some refs to ‘ssh://user@pubip/~user/repositories
    /gitolite-admin.git’

    Thanks in advance!

    • Your gitolite installation is fine. The problem you are facing is based on how you cloned your repository. See the following link, as it outlines the issue you are facing.

      http://stackoverflow.com/questions/5233058/gitolite-push-error-remote-env-gl-rc-not-set

      Ryan

      • Hi,

        Thank you for your reply, yes you are right, installation is ok, but adding new user is problem. When I add new users I still need to use git username to clone, commit, push. Generating and adding new pub keys is only connection from workstation to NAS. Anyway thank you on wonderfull tutorial. Now i have all my project connected with my own git server… Currently trying to figure out how to install git-daemon on NAS to use git protocol :)

        Best regards from Sarajevo
        Pooky

        • Cheers from Cleveland, OH USA!

          It should be easy to get git-daemon serving up the git protocol. Check out the Synology forums and wiki and see what you need to do to daemonize the process.

  7. i follwed all steps but i get this error:

    noname:.ssh Lutarus$ git clone git@192.168.178.21:gitolite-admin
    Cloning into ‘gitolite-admin’…
    FATAL: R any gitolite-admin Lutarus DENIED by fallthru
    (or you mis-spelled the reponame)
    fatal: The remote end hung up unexpectedly

  8. Thank you for this very thorough install, everything went well until I tried to copy over my key to the home directory of the git user on my DiskStation. I got:

    ash: /opt/bin/gitosis-serve: not found
    lost connection

    I had tried to install gitosis a while back without any luck, so I thought I’d give gitolite a try, but it looks like gitosis left a trace somewhere even though I removed it from my DiskStation. Might you have a suggestion as to how I can troubleshoot?

    Thanks!

  9. First of all thank you for the comprehensive guide.
    I successfully installed git and created the git user, but when I want to change via “su – git” there appears a warning “su: warning: cannot change directory to /var/services/homes/git: No such file or directory” in fact the whole “homes” directory is non existent. What’s up with that? =(

    I also tried to create the dir via root, but permission is denied … damn.

    Thanks

    • Christian -

      Odd behavior indeed. Try blowing away the git user and trying again? Just to be certain, you created the git user through the admin interface, right? Not through the shell?

    • I had the same problem.
      The solution is to go to the users screen on the control panel of your DiskStation and activate the service ‘Users’s home’ (Sorry, I don’t run English UI, but I’m sure you can figure out which button I’m referring to)

      /Magnus

  10. Thank you so much for going to the trouble of writing-up this tutorial, it has been invaluable to me.

    Just one question; what is the name of the wordpress plug-in you are using to display the code segments? Its really nice.

    Regards
    Alex.

  11. I have the following error when attempting to clone admin repository

    Evgenys-MacBook-Pro:~ evgeny$ git clone git@diskstation:gitolite-adminCloning into ‘gitolite-admin’…
    ssh: Could not resolve hostname diskstation: nodename nor servname provided, or not known
    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.
    Evgenys-MacBook-Pro:~ evgeny$ git clone git@192.168.1.61:gitolite-admin
    Cloning into ‘gitolite-admin’…
    git@192.168.1.61‘s password:
    fatal: ‘gitolite-admin’ does not appear to be a git repository
    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.

    Can you please point me what is wrong? I followed your instructions step-by-step.

    Thanks!

    • My guess based on the information provided is that you missed a step with your ssh key setup.

      Cloning into ‘gitolite-admin’…
      git@192.168.1.61‘s password:

      It shouldn’t be asking for a password, rather it should be using the authorized key.

      • Ok, finally got it working! All keys were fine

        My problem was the SSH was not enabled on the server
        so i changed in the /etc/ssh/sshd_config from

        #RSAAuthentication yes
        #PubkeyAuthentication yes
        #AuthorizedKeysFile .ssh/authorized_keys

        To this:

        #RSAAuthentication yes
        PubkeyAuthentication yes
        AuthorizedKeysFile .ssh/authorized_keys

        Please refer to this great post by Scott Granneman concerning enabling SSH on Synology, it helped a lot to me.
        http://www.chainsawonatireswing.com/2012/01/15/ssh-into-your-synology-diskstation-with-ssh-keys/

        Last thing I did was deleting “no-pty” from .ssh/authorized_keys file
        because it was producing error “PTY allocation request failed on channel 0″ when I was trying to ssh git@192.168.1.61

        I would like to thank you a lot for your effors!

        Really, great job!!

  12. After comment out the 2 lines in ~/.profile I can’t access Diskstation Web Desktop.

  13. Hey Ryan

    First of all, thank you very much for this extremely well documented tutorial. It was very convenient to follow even with my rather basic previous knowledge. The installation worked without any problems on my Synology DS212+!

    Last week I updated DSM to version 4.1 – unfortunatley I completely forgot about possible issues. In fact, I was not able to push my commits to the gitolite-admin repo after the update. I received the error message

    git push
    WARNING: Can’t exec “git”: No such file or directory at /volume1/homes/git/gitolite/src/lib/Gitolite/Common.pm line 120, line 1.

    fatal: The remote end hung up unexpectedly

    After an unsuccessful internet search I started to redo some of the steps of your tutorial which finally fixed my problem. In fact, I don’t know which steps really are necessary, maybe someone with more insight can clarify that.

    Here’s what I (re)did after the DSM update 4.0->4.1:

    - From section “Bootstrap and Install Git on your Diskstation”: steps 4, 10-17 (in my case coreutils were still up-to-date, so step 15 was unnecessary)
    - From section “Install SCP (optional)”: nothing, scp still working
    - From section “Create a Git user on the Diskstation”: nothing
    - From section “Enable Shell Access for the Git User”: nothing, git user entry unchanged
    - From section “Generate a Key Pair on your Local Workstation”: nothing
    - From section “Configure the Git Hosting User’s Profile and Home Directory”: steps 1-5 (in my case the .profile was unchanged, so step 3 and 4 unnecessary)
    - From section “Install Gitolite on the DiskStation and Run Setup”: nothing
    - From section “Clone the Admin Repo”: nothing
    - Reboot
    - Now you’re hopefully done!

    Please post, if I forgot/messed up something! I hope this helps someone with the same issue!

    Best regards
    Daniel

    • Thanks, Daniel. I hope this helps out some others that upgrade/have upgraded. I haven’t found the time to go through my tutorial with 4.1 yet, so thanks for sending this feedback along for others!

    • Same problem here.

      I had to redo the following command to have it working again:
      ln -s /opt/bin/git* /usr/bin

  14. Have same problem as Daniel in post #13

    Followed these instructions and got i working again, only difference is that I only applied
    - From section “Bootstrap and Install Git on your Diskstation”: steps 4, 10-17 (skipping 15)
    Thansk Daniel

    Best regards
    Per-Åke

  15. Great Article!!! So easy to follow and complete. Thanks for documenting this!

  16. Awesome! thank you so much for posting this – everything works perfectly.

    Just wondering: why did you comment out (and leave commented out) the root .profile PATH var? It seems that the step where you symlink the git binaries to the normal path (/usr/bin) covers any path issues.

    Also wondering, have you found that you need to redo any of these steps after upgrading your DSM? If so, what step(s)?

  17. [...] is not supported by DSM trough the package center, but the IPKG repository contains it. Ryan Helco (http://www.bluevariant.com/2012/05/comprehensive-guide-git-gitolite-synology-diskstation/) took the effort to write down the necessary steps to set it [...]

  18. Hi Ryan,

    Thanks for the article – it has helped me a lot to do almost the complete setup :)

    I am, however, stumbling at the final hurdle and don’t understand something.

    When I run > gitolite setup -pk $HOME/username.pub
    I get the following: WARNING: keydir/usernamepub duplicates a non-gitolite key, sshd will ignore it

    The problem is, I use username.pub for SSH login for the user “git”, and “git” has shell access (as per your instructions above).

    Should I understand it that the username key pair generated are only used for gitolite and thus any user defined access to the server using SSH should use other keys? Also, is there a reason why the default id_rsa should be used?

    I’ll comment further if I manage to fix by generating other keys.

    Thanks again,
    Sonny

  19. Hi,

    I have problem while installing git.

    I have stopped on this step:

    DiskStation> gitolite setup -pk $HOME/tom.pub
    FATAL: errors found but logfile could not be created
    FATAL: /volume1/homes/git/.gitolite/logs/gitolite-2013-02.log: No such file or directory
    FATAL: die '/volume1/homes/git/tom.pub' must have exactly one line
    DiskStation> FATAL: die '/volume1/homes/git/tom.pub' must have exactly one line

    I resolve missing directories .gitolite and .gitolite/logs/ by creating this in console and it is ok.
    Unfortunately second error still exists (FATAL: die ‘/volume1/homes/git/tom.pub’ must have exactly one line) and I don’t know what’s wrong.

    I have DSM 4.1 on DS212j. Early I had DSM 4.0 but I did not install git on DSM 4.0.

  20. Thank for answer.
    I done a key in puttygen on Windows 8. On one of pages on link from You I found information about issues with putty and recommendation to use msysgit (http://msysgit.github.com/).  I installed it but I ran my second computer with CentOS 6 and I finished on this. After command: gitolite setup -pk $HOME/tom.pub I saw  this:

    DiskStation> gitolite setup -pk $HOME/tom.pub
    Initialized empty Git repository in /volume1/homes/git/repositories/gitolite-admin.git/
    WARNING: pclose failed: Illegal seek at /volume1/homes/git/gitolite/src/lib/Gitolite/Common.pm line 317.

    WARNING: pclose failed: Illegal seek at /volume1/homes/git/gitolite/src/lib/Gitolite/Common.pm line 317.

    Initialized empty Git repository in /volume1/homes/git/repositories/testing.git/
    WARNING: Warning: Use of “shift” without parentheses is ambiguous at /volume1/homes/git/gitolite/src/triggers/post-compile/ssh-authkeys line 124, <DATA> line 1.

    WARNING: /volume1/homes/git/.ssh missing; creating a new one
    WARNING: /volume1/homes/git/.ssh/authorized_keys missing; creating a new one

    I finished all steps and It seems that all is ok…. probably :)

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>