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 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)
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 renameid_rsa.pub
toauthorized_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/
@mahoromax the most likely cause of issues with your gituser is the permissions. Check the following permission.
~gituser/.
in bash) should be owned by gituser and have 711 permissionrwx--x--x
~gituser/.ssh/.
owned by gituser and 711 permissionsrwx--x--x
)~gituser/.ssh/authorized_keys
owned by gituser with 600 permissionsrw-------
).For the git access check that the permissions on the git repository, the git directory and that git has been initialized.
ls -la /volume1/git/.
The dot directory
.
should have the following permissionsdrwx------+ 1 gituser root 186 Apr 4 02:08 .
The repository directory should have the following permissions
drwx------+ 1 gituser users 98 Apr 4 02:08 SynologyGitUsability.git
My example git repository is called
SynologyGitUsability.git
cd SynologyGitUsability.git
git update-server-info
**If you don't yet have a git repository **
The following command sequence is the easiest to create one for testing. You will need to complete step two to update-server-info after creating the first git repository.
You need
root
oradmin
access.sudo -u gituser bash
cd /volume1/git
git --bare init TestRepository.git
Finally remember when adding the repository into windows, linux or OS X git tools you must use the full name
TestRepository.git
.Tell if this helps or provide more details on what is going wrong. Good luck!