Running Git on a Synology NAS

Step 1: Enable SSH

Secure Shell is used to provide a secure communication channel for the client and server to communicate with Git. Enable ssh if it is not already enabled.

  • From the Synology Control Panel select Terminal.
  • Select “Enable SSH service” from the Control Panel.

EnableSSH

Step 2: Create a git repository share

Create a new file share to hold the git repository (/volume1/git).  Give it admin and user permissions.

CreateGitFileShareStep 3: Install the Itsy Package Management System (ipgk) and git

Logon to the diskstation through a ssh client, I used putty.

Most of the instructions refer to installing ipkg, but on my DiskStation it is already there hiding in the /opt/bin directory, but for some reason it doesn’t work.  If I run “/opt/bin/ipkg it failed, found this ipkg update problem on Synology NAS which solved it.  Though I just did:

export PATH=/opt/bin:$PATH

I did an "ipkg update", and then

/opt/bin/ipkg install gitsu

Step 4: Create the Git User

Use the web interface to create the git user. A good user name is “git”, allowed user group privs only.

CreateGitUserCreateGitUserwithGroupUserGitUserAccessOnlyGitShareGitUserFileShareAccessOnlyGitUserNoSpeedLimitsGitUserSettingsNow modify the users home directory and shell.  Login in to the diskstation as root and edit the settings in /etc/passwd.  Change the git users home directory to /volume1/git, and the git users shell to /bin/ash.

Next modify the git users PATH to include /opt/bin.  This is done by editing the .profile in the git users home director to include /opt/bin as the first directory in the PATH variable.

[This is all covered in ti57.blogspot..]

Step 4: Check that git is working

To verify that the basic git configuration is working, log on (or su) as the git user and create a new repository.

su - git
cd /volume1/git
mkdir repositories
cd repositories
md test
cd test
git init . --bare

 Step 5: Confgure SSH public keys

Edit /etc/ssh/sshd_config and change the Lines regarding Public Key Authentication:

...
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys
...

Restart sshd:

/usr/syno/etc/rc.d/S95sshd.sh restart

Oddly this sometimes only works half way. If your sshd does not come back, simply switch it back on in the Web interface.

Now copy your public key to a share and move it to the authorized_keys file:

mkdir -p /volume1/home/user1/.ssh
mv /volume1/someshare/id_dsa.pub /volume1/home/user1/.ssh/authorized_keys

Now you should be able to log in without a password.

Also needed:

If you’re sure you’ve correctly configured sshd_config, copied your ID, and have your private key in the .ssh directory, and still getting this error:

Permission denied (publickey).

Chances are, your /home/<user> or ~/.ssh/authorized_keys permissions are too open by OpenSSH standards. You can get rid of this problem by issuing the following commands:

chmod go-w ~/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

———————

References:

Leave a Reply

Your email address will not be published. Required fields are marked *