Instructions for setting up a git server on a Synology NAS with Diskstation. Specifically, I am using a DS414 with DSM 5.0.
- 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 forgituser
andadmin
. 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)
- create
~/.ssh
folder for gituser on server
ssh [email protected]
mkdir /volume1/homes/gituser/.ssh
- copy public rsa key from local computer to gituser account on server
scp ~/.ssh/id_rsa.pub [email protected]:/volume1/homes/gituser/.ssh
- connect via SSH as
root
and renameid_rsa.pub
toauthorized_keys
on NAS (or append if already exists,cat id_rsa.pub >> authorized_keys
)
ssh [email protected]
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
- create bare repo as root
ssh [email protected]
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.
- Clone repo from NAS
git clone ssh://[email protected]/volume1/git/<repo-name>.git
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/
Create repositories remotely using supported mechanism
Thank you for this guide! It is extremely useful. Thank you @walkerjeffd
The notes regarding permissions are very important in current Synology builds (thanks @gazgeek and @jerryfromearth).
However the usability needed improving
I was finding it annoying needing to use ssh to login to the Synology and run several commands so that I could create new repositories and do settings. Also I normally have
admin
disabled, as a security measure and only reenable when required (DSM Control Panel) so it was extra tedious.To create
NewRepo.git
it could be as simple as runningssh [email protected] "git-create-repository NewRepo.git"
on your local machine.This guide will show you how to setup repositories remotely with one command.
Note: this uses fully supported features and should work through DSM upgrades and Git version updates. It uses an ability in git-shell to specify additional commands. This guide shows you how to do it and how to use it. Everything is designed around cut and paste.
ssh [email protected]
sudo -u root bash
/volume1/git
to begituser
.chown -R gituser:user /volume1/git
~gituser
and then create agit-shell-commands
directory in the home directory ofgituser
~gituser/git-shell-commands
no-interactive-login
script to prevent interactive logins now that this functionality is enabled. To make things easy the following can be copy and pasted directly into the shell and it will create the file.help
file to provide instructions or information. I put very little effort into thisgit-create-repository
file to create new repositories as required.This script does have error checking and some security features but if you are concerned later please delete or remove execution permissions later.
Check the GIT_HOME setting in this script and edit if required before cutting and pasting
git-shell-commands
directory to be owned bygituser
and have read and execute permission only.~gituser
./volume1/git
is ready. I have recycle bin on but #recycle may not exist in your directoryhelp
command. I am usingdiskstation.local
as the Synology host name.ssh -l gituser diskstation.local help
git-create-repository
.Example is
ssh -l gituser diskstation.local help "git-create-repository SynologyGitUsability.git"
SynologyGitUsability.git
. Use git push --mirror to populate. An example would begit push --mirror ssh://[email protected]/volume1/git/SynologyGitUsability.git/
Remember to be in a directory containing a local git repository
/volume1/git
/volume1/git
. I added an Empty.git so you can see one without dataThis is the end. So far...
I will be loading all this code onto Github and sharing code and details. Look at SynologyGitUsability in @dmurphyoz