Skip to content

Instantly share code, notes, and snippets.

Embed
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/

@steathy
Copy link

steathy commented Dec 20, 2020

Hi, thanks for your above comments,
this is what I have done on my Synology.

On Diskstation interface.

  1. Create gituser.
  2. Create git shared folder.
  3. Grand access for gituser to the shared folder.
  4. Enable SSH access (Control Panel > Terminal & SNMP > Enable SSH Service)
  5. Install Git Server package.
  6. Open Git Server and allow gituser permissions.

On local computer. (Generate SSH key pair and copy public key to Diskstation)

ssh-keygen -t rsa -b 4096
scp ~/.ssh/id_rsa.pub admin@diskstation.local:/tmp

On Diskstation SSH. (Create Git repository, configure permissions and SSH Server )

ssh admin@diskstation.local
cd /volume1/git
git init --bare --shared myrepo.git
cd ./myrepo.git
git update-server-info
sudo ls -s /volume1/git/myrepo.git /myrepo.git
sudo su -
mkdir /volume1/homes/gituser/.ssh
cat /tmp/id_rsa.pub >> /volume1/homes/gituser/.ssh/authorized_keys
chown -R gituser:users /volume1/homes/gituser/.ssh
chmod 755 /volume1/homes/gituser
chmod 711 /volume1/homes/gituser/.ssh/
chmod 600 /volume1/homes/gituser/.ssh/authorized_keys
vim /etc/ssh/sshd_config
    RSAAuthentification yes
    PubkeyAuthentification yes
synoservicectl --reload sshd

On local computer.
git clone ssh://gituser@diskstation.local/myrepo.git

Thank you very much for your great instructions!

I think there's a typo "sudo ls -s". It should be "ln" instead of "ls".

@szpeter80
Copy link

It seems Synology removed interactive command support in their packaged version of git:

https://community.synology.com/enu/forum/8/post/147518

If you get the 'fatal: git package does not support interactive shell' messages, then that's why.

A workaround (discussed in the linked forum) to remove the Syno package, install community, get the git-shell executable, remove community and reinstall Syno git package, and overwrite their version of git-shell. You have to do it as root so be careful what you type.

Multiple units, DSM7.0, Synology GIT server package: 2.26.2-1015

@whytong
Copy link

whytong commented Oct 24, 2021

@dmurphyoz I have been trying to follow your scripts but the problem I ran into is that the remote execution could not find these scripts.
running a remote env command gives PATH=/usr/bin:/bin:/usr/sbin:/sbin. The login shell of gituser is /bin/sh, I tried to add a ~/.profile, ~/.shinit file, did not load, I also tried to change the login shell to /bin/bash but then access was denied. Could you provide more insight? I'm using DSM7 btw.

Create repositories remotely using supported mechanism

Thank you for this guide! It is extremely useful. Thank you @walkerjeffd

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