Create a gist now

Instantly share code, notes, and snippets.

Instructions for setting up git server on Synology Diskstation

Configure Synology NAS as Git Server

Instructions for setting up a git server on a Synology NAS with Diskstation. Specifically, I am using a DS414 with DSM 5.0.

Set Up User and Folder

  • Create user gituser via Diskstation interface (with File Station and WebDAV privilages)
  • Add new shared folder called git (located at /volume1/git) with read/write access for gituser and admin. This folder will hold all the repos.
  • Install Git Server package via Diskstation
  • Open Git Server and allow gituser permissions
  • Enable SSH access on Diskstation (Control Panel > Terminal & SNMP > Enable SSH Service)

Configure SSH Access

  • create ~/.ssh folder for gituser on server
ssh admin@diskstation.local
mkdir /volume1/homes/gituser/.ssh
  • copy public rsa key from local computer to gituser account on server
scp ~/.ssh/id_rsa.pub admin@diskstation.local:/volume1/homes/gituser/.ssh
  • connect via SSH as root and rename id_rsa.pub to authorized_keys on NAS (or append if already exists, cat id_rsa.pub >> authorized_keys)
ssh root@diskstation.local
mv /volume1/homes/gituser/.ssh/id_rsa.pub /volume1/homes/gituser/.ssh/authorized_keys
  • change permissions while logged in as root
cd /volume1/homes/gituser/
chown -R gituser:users .ssh
chmod 700 .ssh
chmod 644 .ssh/authorized_keys

Set Up New Repo on NAS

  • create bare repo as root
ssh root@diskstation.local
cd /volume1/git/
git --bare init <repo-name>.git
chown -R gituser:users <repo-name>.git
cd <repo-name>.git
git update-server-info

NOTE: I'm not entirely sure if git update-server-info must be run for each repo or just initially. It seems to work without running this command, but I'm suspcicious that it might cause problems later.

Add NAS as Remote for Local Repo

  • Clone repo from NAS
git clone ssh://gituser@diskstation.local/volume1/git/<repo-name>.git

References

http://blog.osdev.org/git/2014/02/13/using-git-on-a-synology-nas.html http://stackoverflow.com/questions/20074692/set-up-git-on-a-nas-with-synologys-official-package http://www.heidilux.com/2014/02/setup-git-server-synology-nas/

@gazgeek
gazgeek commented Aug 19, 2015

Hey.

Just wanted to say thanks - this has been really helpful in getting git up and running on my DS415+.

I ran in to a couple of issues.

  • I had to specify --shared in the git init command otherwise I got errors about the config directory being inaccessible...

git init --bare --shared <repo-name>.git

  • I couldn't get the password-less login to work unless I set the authorized_keys permissions to 600...

chmod 600 .ssh/authorized_keys

Cheers!

@jerryfromearth

Hi,

Thanks for the post!

  • To make "password-less ssh" work, aside from @gazgeek's suggestion, I also find out that I need to change the permission of the user folder (that contains .ssh) to 755. Previously it was 711:
chmod 755 /home/gituser

Reference:
http://superuser.com/questions/736055/ssh-with-no-password-passwordless-on-synology-dsm-5-as-other-non-root-user

@jgudpns
jgudpns commented Nov 6, 2015

Jeff - Trying to do this to my DS214, but I get stuck on understanding about how to get the rsa keys and where on my local (pc?) this would be.

Also - does "diskstation.local" by the name of the DS214?

@eyesuk
eyesuk commented Jan 3, 2016

Does anyone know if this package includes jekyll functionality like github?

@natejlong

@eyesuk You could add git commit hooks on the server so that it built the jekyll site on every push up to it. You could then symlink the output directory to the web folder on the NAS and follow the steps here

@ix-xerri

There is no /volume1/homes/ directory. Any other options or do I have to create them?

@vanlooverenkoen

Is there any GUI I can use with this? because the shell isn't that practical

@robertveringa89

Thank you for this!

@greyshine
greyshine commented Feb 5, 2017 edited

Thank you for your post.
I do stumble with "Open Git Server and allow gituser permissions".
I do not find anything to edit anything with the installed Git server.

As I understand it from your explanation, there is a Git-Server/Settings/Users navigation path to manage/add users.

Note: I just found it. I always looked at the installed packages in the Package Center. But it is located at the "Main Menu". The place where all installed applications have their starting home.
synology-gitserver

Another issue I watched (if I got it right):
It is metioned that git update-server-info is somewhat needed; probably also or instead it is needed to set the chown again. I had the 'feeling' that the git server places new files into his .git folder with root:root ownershipwhich breaks the git commands executed as/from client.

@ockertbotha
ockertbotha commented Feb 10, 2017 edited

ssh as root is no longer supported
ssh root@diskstation.local

Instead:

ssh admin@diskstation.local
sudo -i

https://www.synology.com/en-us/knowledgebase/DSM/tutorial/General/How_to_login_to_DSM_with_root_permission_via_SSH_Telnet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment