Installing git on Qnap
I needed to install git on my qnap 219P and 219P+. I found the existing howtos inconsistent and confusing so I thought this might come handy for people like me who want to setup a git repository on their qnap. Here is what I finally did…
Firmware Update
First I had to do a firmware update. At time of writing 3.7.3 was available. I downloaded, unpacked and uploaded the “TS-219_20120801-3.7.3.img” file to my qnap via the admin interface.
Setup Networking
I did this setup while I carried the qnap on a business trip. I had no network switch or dhcp server with me. Instead I wanted to connect the qnap directly via ethernet cable to my ubuntu laptop.
If you access the qnap through your home or office network and it already has IP and internet access you must not follow the steps for “Setup Networking”.
For installing packages on the qnap I had to share the wifi connection. The most convenient way for me was to set the method to “Shared to other computers” in network connections:
Once connected the qnap gets an IP address and also the laptop.
You can find out the one of the laptop:
# ifconfig
To find out the IP of the qnap is a little bit trickier:
# nmap -sP 10.42.0.*
Nmap will list <your qnap IP> which you will use for all steps. To access the admin GUI of the qnap type http:<your qnap IP>:8080
Enable admin account to use ssh
Be sure SSH is enabled. In the Administration interface, go to Network Services, then to Telnet / SSH. Be sure the box Allow SSH connection is checked. Note the port number in the adjacent text box, and change it if desired. If you changed anything, click the Apply button.
Now you are able to ssh into your qnap as admin user:
ssh admin@<your qnap IP>
Add IPKG
In the device’s Administration interface, select the ‘System Tools’ -> ‘QPKG’ page, click on ‘Get QPKG’ button.
QPKG provides a nice admin interface to install additional packages right from your qnaps admin GUI. Here is how the installed Optware IPKG package looks like:
Use IPKG to install git
Ssh into your qnap and install git:
# ssh admin@10.41.0.98
List the available packages relevant for git:
# ipkg list|grep git
Install git:
# ipkg install git
Add ssh daemon openssh
The default configuration for qnap only allows the admin user access via ssh. In order to login other users than admin one needs to install openssh.
I found it the easiest to simply add the openssh daemon to the already existing one. I just changed the existing ssh port configuration via the admin GUI to 222. This makes room for openssh to use port 22.
Use ssh to access your qnap:
# ssh admin@<your qnap IP> -p 222
Install the Openssh package using Optware:
# ipkg update
# ipkg install openssh
mount -t ext2 /dev/mtdblock5 /tmp/config
Just add “/opt/sbin/sshd &” to autorun.sh in /tmp/config and make it executable:
# chmod a+x /tmp/config/autorun.sh
Then reboot:
# reboot
Setup a git repository
I used the qnap admin GUI to create a “SHARE FOLDER” git.
Ssh into your qnap with the admin account:
# ssh git@<your qnap IP>
Now setup the new repository:
# cd /share/git/
# mkdir NEW.git
# cd NEW.git
# git –bare init
I also wanted to collect the ssh authorization key from my developer machine (from ~/.ssh/id_rsa.pub) so I do not have to provide a password each time I commit something to the repository:
# cd /share/git/
# mkdir .ssh
# touch .ssh/authorized_keys
# chmod 700 .ssh/
# chmod 600 .ssh/authorized_keys
Openssh is very concerned about permissions and ownership of files especially of the home directory. I had (in the qnap admin GUI) set advanced options / advanced folder permissions. Then I could set git as owner of the /share/MD0_DATA/git folder. After I reduced the permissions to 700 it all worked:
# chmod 700 /share/MD0_DATA/git
Now copy the public key from your development machine (this only works for single keys, if you have multiple you will have to add them one key per line.):
# scp ~/.ssh/id_rsa.pub git@<your qnap IP>:.ssh/authorized_keys
Setup git user account
Create user account “git” in the qnap admin GUI
Ssh into your qnap with the admin account:
# ssh admin@<your qnap IP>
Check that the home directory is correctly configured as /share/git:
# cat /etc/passwd
Using the new repository
You can for example clone the new repository from your developer machine:
# git clone git@<your qnap IP>:/share/git/NEW.git
Cleaning up
Now you do not want that the git users to open a terminal on the qnap.
Ssh into your qnap with the admin account:
# ssh admin@<your qnap IP>
Set git-shell for the git user in /etc/passwd:
admin:x:0:0:administrator,,,:/share/homes/admin:/bin/sh
guest:x:65534:65534:guest:/share/homes/guest:/bin/sh
git:x:500:100:Linux User,,,:/share/git:/opt/bin/git-shell
httpdusr:x:99:100:Apache httpd user:/tmp:/bin/sh
We want to make sure that terminal access is prohibited so I try it out:
# ssh git@<your qnap IP>
fatal: Interactive git shell is not enabled.
Connection to <your qnap IP> closed.
Debugging the openssh daemon
Ssh into your qnap with the admin account to the original sshd:
# ssh admin@<your qnap IP> -p 222
Stop openssh
# ps -ef | grep /opt/sbin/sshd
3572 admin 1048 S /opt/sbin/sshd
5735 admin 588 S grep /opt/sbin/sshd
# kill 3572
Run openssh in debug mode:
# /opt/sbin/sshd -ddd
Committing an existing repository
This scenario describes how to initialize a repository from an existing folder on your developer machine (make sure the repository exists on the qnap).
… on your developer machine:
# cd myproject
# git init
# git add .
# git commit -m ‘initial commit’
# git remote add origin git@<your qnap IP>:/share/git/NEW.git
# git push origin master
More Information
You can install IPKG package by QPKG and then install git by IPKG.
http://wiki.qnap.com/wiki/Install_Optware_IPKG
http://wiki.qnap.com/wiki/How_to_SSH_into_your_QNAP_device
http://wiki.qnap.com/wiki/How_To_Replace_SSH_Daemon_With_OpenSSH
now install git via IPKG:
http://www.wonko.de/2010/04/set-up-git-on-synology-nas.html
cool intro on linux:
http://www.corvidworks.com/articles/self-hosted-remote-git-repositories
issues on permissions and directory / file ownership:
http://unix.stackexchange.com/questions/4484/ssh-prompts-for-password-despite-ssh-copy-id









