Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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

This comment has been minimized.

Show comment Hide comment
@gazgeek

gazgeek 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!

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

This comment has been minimized.

Show comment Hide comment
@jerryfromearth

jerryfromearth Sep 27, 2015

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

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

This comment has been minimized.

Show comment Hide comment
@jgudpns

jgudpns 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?

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

This comment has been minimized.

Show comment Hide comment
@eyesuk

eyesuk Jan 3, 2016

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

eyesuk commented Jan 3, 2016

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

@natejlong

This comment has been minimized.

Show comment Hide comment
@natejlong

natejlong May 13, 2016

@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

@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

This comment has been minimized.

Show comment Hide comment
@ix-xerri

ix-xerri Sep 19, 2016

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

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

@vanlooverenkoen

This comment has been minimized.

Show comment Hide comment
@vanlooverenkoen

vanlooverenkoen Nov 23, 2016

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

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

@robertveringa89

This comment has been minimized.

Show comment Hide comment
@robertveringa89

robertveringa89 Jan 27, 2017

Thank you for this!

Thank you for this!

@greyshine

This comment has been minimized.

Show comment Hide comment
@greyshine

greyshine Feb 5, 2017

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.

greyshine commented Feb 5, 2017

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

This comment has been minimized.

Show comment Hide comment
@ockertbotha

ockertbotha Feb 10, 2017

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

ockertbotha commented Feb 10, 2017

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

@ahmadalbakri

This comment has been minimized.

Show comment Hide comment
@ahmadalbakri

ahmadalbakri May 13, 2017

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

Can be shorten to -> git clone ssh://diskstation/git/< repo-name >.git

How-to:

  1. change diskstation by editing ~/.ssh/config . Example https://mediatemple.net/community/products/grid/204644730/using-an-ssh-config-file

  2. symlink git in root(/) to target git folder as above /volume1/git

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

Can be shorten to -> git clone ssh://diskstation/git/< repo-name >.git

How-to:

  1. change diskstation by editing ~/.ssh/config . Example https://mediatemple.net/community/products/grid/204644730/using-an-ssh-config-file

  2. symlink git in root(/) to target git folder as above /volume1/git

@aalaran

This comment has been minimized.

Show comment Hide comment
@aalaran

aalaran Jul 5, 2017

git update-server-info saved me a headache. Thanks!

aalaran commented Jul 5, 2017

git update-server-info saved me a headache. Thanks!

@jforstneric

This comment has been minimized.

Show comment Hide comment
@jforstneric

jforstneric Mar 3, 2018

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

I think this gets created when you first create a normal user through DSM. There's also a simlink in /var/services that points to /volume1/homes.

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

I think this gets created when you first create a normal user through DSM. There's also a simlink in /var/services that points to /volume1/homes.

@byverdu

This comment has been minimized.

Show comment Hide comment
@byverdu

byverdu Mar 21, 2018

When I was logging as admin using SSH was throwing the following error:

Could not chdir to home directory /var/services/homes/admin: No such file or directory

Which relates to:

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

I found a post that explains how to create the folder by enabling some settings in DSM https://www.chainsawonatireswing.com/2012/01/16/log-in-to-a-synology-diskstation-using-ssh-keys-as-a-user-other-than-root/

Basically go to Control Panel > User > Advanced > User Home > Enable user home service

🎉

Thanks for putting all this info together 🚀

byverdu commented Mar 21, 2018

When I was logging as admin using SSH was throwing the following error:

Could not chdir to home directory /var/services/homes/admin: No such file or directory

Which relates to:

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

I found a post that explains how to create the folder by enabling some settings in DSM https://www.chainsawonatireswing.com/2012/01/16/log-in-to-a-synology-diskstation-using-ssh-keys-as-a-user-other-than-root/

Basically go to Control Panel > User > Advanced > User Home > Enable user home service

🎉

Thanks for putting all this info together 🚀

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