Showing posts with label ssh. Show all posts
Showing posts with label ssh. Show all posts

Sunday, March 24, 2013

Installing Git and Gitolite on a Raspberry PI

If you want to give a try to Git @home (and are not interested by GitHub), installing Gitolite on a Raspberry PI is one of the best option you have, even better than installing git on a Synology NAS (in the case you do not want to tweak your Synology device).
A Raspberry PI in a plastic case.

All you have to do is to:
  • order a Raspberry PI model B (less than € 35) and some accessories. Here you have a list of compatible items you can use with a PI. Additionally to my PI, I bought :
    • an USB power supply (~ € 7-12. Beware; output must be at least 1A)
    • a clear moulded plastic case to house the PI  (~ € 6)
    • a Transcend TS32GSDHC10E  32 GB SDHC class 10 memory card (~ € 24. Could be less sized. Initially I wanted to have enough space to host an artifacts repository)
    • an Edimax EW-7811UN USB Nano adapter Wireless 150 Mbps (~ 12 €. required only if you want to place your PI out of reach of an Ethernet plug)
  • allow ssh access to your PI (gitolite or not, this is something you will do during the first setup under Raspbian Wheezy ...)
  • install git and perl on your PI using the usual apt-get install commands
  • useradd a git account
  • follow the installation instructions of Gitolite as you can found them on the GitHub repository. 
Gitolite enables you to setup a server of  git repositories on a dedicated host. Access control is based on user's public SSH keys, and access to each repository can be controlled per user or group of users.

There is no need for a GUI to administrate a Gitolite server; a particular git repository, gitolite-admin (that you have to clone on your workstation as any other repository) is used to create and configure repositories, and to grant rights to users.

The initial conf/gitolite.conf file of the gitolite-admin project gives at the first sight an idea of the main principle of gitolite:

repo gitolite-admin
    RW+     =   bob

repo testing
    RW+     =   @all

You are bob, you have installed gitolite on the PI (and as you give your public key bob.pub  during installation, your are granted to administrate the gitolite-admin repository). Every known user (@all) is granted to use git-fully the repository testing.

If you want to add a new repository named myrepo1 to your gitolite server, you just have to clone the gitolite-admin repository on your development workstation, and add the following lines to conf/gitolite.conf:

repo myrepo1
    RW+     =   bob
    R       =   alice

Alice being a new "read only" player, you also have to add her public key named alice.pub into the keydir directory of the gitolite-admin project.

Add, commit, and push; et voilà ! Your new repository myrepo1 is  clonable by Bob and Alice.

Instructions for deleting a repository can be found here.

Even if you do not use your Synology device to host a git server, you can still use it to backup your Raspberry's Gitolite repositories with rsync. This is another story ...




References:



Friday, January 4, 2013

How to setup a git server on a Synology NAS

Context

  • Software development (Linux, MacOS, Java / Eclipse)
  • Home network (security is not a concern in this context)
  • Synology NAS (DS 112j, DSM 4.1) 
Important update (august 31th 2013):  since I wrote this post, Synology has incorporated a Git server with the DSM 4.3. So what follows is deprecated...

Nevertheless, you may find that it is far more simpler and powerful to setup a git server on a Raspberry PI using Gitolite.

This memo describes how to setup a Git over SSH server on a Synology NAS. Use it at your own risk ! Your context certainly differs from mine ...



Enable SSH on the Synology
First of all, SSH must be activated on the NAS. This can be done using the  Control Panel of the DSM and the Terminal app. SSH will be used to connect to the Synology, and as the communication protocol for Git.

Bootstrap ipkg

As git is not installed by default on Synology devices (like many useful Unix commands), one has to extend the DSM using ipkg, the Itsy package manager, dedicated to Debian based embedded devices.

More information (and disclaimers) about modifying Synology devices can be found here.

Identify the bootstrap file

The first thing to do is to identify what is the corresponding bootstrap file for your Synology device (popular bootstrap URLs are here).

Log into the NAS

Then  log into the Synology device (diskstation2 in this example) using ssh:

% ssh root@diskstation2
root@diskstation2's password: 

BusyBox v1.16.1 (2012-09-26 03:28:29 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

DiskStation2#

(I changed the original prompt which ends with a redirection sign ">". I hate redirection signs in prompts...)

Get the bootstrap file

Get the bootstrap file (for a DS112j target in this example) in a temporary directory and install it:

DiskStation2# cd /volume1/@tmp
DiskStation2# wget http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/syno-mvkw-bootstrap_1.2-7_arm.xsh



Run the bootstrap

DiskStation2# sh syno-mvkw-bootstrap_1.2-7_arm.xsh

then do some cleaning:

DiskStation2# rm syno-mvkw-bootstrap_1.2-7_arm.xsh


Modify root's user PATH

Modify root path in .profile: include /opt/bin and /opt/sbin at the beginning of the PATH variable (/opt is where ipkg installs things, /opt/sbin being useful if you want to install commands like lsof).


Reboot the NAS 

(don't forget to warn your family users ...)

DiskStation2# reboot now

(or use the web interface, in any case, you must hear the born again beep ...)

Install packages

Log again and install required packages:

DiskStation2# ipkg install coreutils


DiskStation2# ipkg install git





Make symbolics links of git commands into /usr/bin 



This is a simple way to make these commands available via sshd.

DiskStation2# for f in `ls /opt/bin/git*`
> do
> ln -s $f /usr/bin     
> done

Alternative: use ~git/.ssh/environment and modify /etc/ssh/sshd_config to set PermitUserEnvironment to yes as explained here.

Create a git user on the NAS

Use the web interface to create a git user (belonging to the group users) with no privileges.

Several extra steps are required :

As root user
  • Change some fields of the git user in /etc/passwd (using vi)
    • Replace the home directory
      • /var/services/homes/git to /volume1/git
    • Replace the login shell
      • /sbin/nologin to /bin/ash
As git user
  • Become the git user : DiskStation2# su - git
  • Just to be sure, check that the git user homedir belongs to the git user (this should be the case)
  • Create a .profile file 
    • Copy and adapt the root's .profile file
    • Don't forget to change the HOME variable accordingly (I did not understood why the HOME var is not setup automatically ...)
  • chmod to 700 the git user homedir
  • create a  .ssh folder within the git user homedir, again with 700 perms
Note: I realized sometime later that relocating the homedir of the git user on /volume1 had the side effect of creating automatically (at the next reboot) a git share. Using the web interface, I then disabled this share for the members of the users group, and hide it from the Network places.

Authorize git users

As the git user just created on the Synology will be accessed for git purposes using the SSH protocol by your development account, you must add its public key in the ~git/.ssh/authorized_keys file (whose permissions must be 600).

Doing this will also let you access to the git account of the Synology from your development account securely and without supplying a password.

I used vi and copy / paste between xterms  to copy my public key in the authorized_keys file.

If your are not familiar with SSH and public/private keys, you should read this article (how to create a private/public key pair, how to include the public key in an remote authorized_keys file).

If the following command fails (replace diskstation2 by the IP name of your NAS) or prompts you for a password, it means that your SSH setup is not correct:

myself@myhost:~/% ssh git@diskstation2 ls /etc/shells
/etc/shells

Test the git server

On the Synology

  • Create a repositories folder in the git homedir
  • cd to it, then create a git repo:
git@DiskStation2% echo $PWD
/volume1/git/repositories

git@DiskStation2% mkdir aiuto.git
git@DiskStation2% cd aiuto.git/
git@DiskStation2% git init --bare
Initialized empty Git repository in /volume1/git/repositories/aiuto.git/
git@DiskStation2% ls
HEAD  branches  config  description  hooks  info  objects  refs

On a client workstation

myself@myhost:~/dev/projects% git clone ssh://git@diskstation2/volume1/git/repositories/aiuto.git
Cloning into 'aiuto'...
warning: You appear to have cloned an empty repository.
myself@myhost:~/dev/projects% ls -a aiuto/
.  ..  .git
myself@myhost:~/dev/projects% cd aiuto/
myself@myhost:~/dev/projects/aiuto% echo "V0.1 - 2 janvier 2013" > Changes.txt
myself@myhost:~/dev/projects/aiuto% git add Changes.txt
myself@myhost:~/dev/projects/aiuto% git commit -m "Changes.txt file created - release notes"
[master (root-commit) 82fcd36] Changes.txt file created - release notes
 1 file changed, 1 insertion(+)
 create mode 100644 Changes.txt
myself@myhost:~/dev/projects/aiuto% git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 267 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To ssh://git@diskstation2/volume1/git/repositories/aiuto.git
 * [new branch]      master -> master


References

Links bellow helped me to work on this topic.

http://www.wonko.de/2010/04/set-up-git-on-synology-nas.html
http://www.bluevariant.com/2012/05/comprehensive-guide-git-gitolite-synology-diskstation/
http://stackoverflow.com/questions/10888300/gitosis-vs-gitolite (reading one of the answers, I decided to not use gitolite to begin with git; being the only software developer in casa ...).


Note: An alternative to install git on a Synology device
A Raspberry PI 512MB in a box.
Git friendly !
 is to install it on a Raspberry PI. For those of you who don't know, a Raspberry is an affordable credit card sized computer, running under Linux (particularly Raspbian which is a Debian derivative), equipped with 512MB of memory, and which uses using a SD Card as a storage device.