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/
Hi @AllNickNamesAreBusySoITakenThis and @CameronD73
It's been a while since I have been on this thread and currently I am in another country to my Synology.
There are several ways to achieve this:
Mesh VPN (e.g. TailScale)
Using a Mesh VPN like TailScale (merely an example but a version is available for Synology) you can install a client on your Synology which will create an outbound tunnel from your Synology machine. This can either expose services in this case SSH via Port 22 or one or more systems on the local network with the Synology.
A client machine running the Mesh VPN client and logged into your network can then see this as though it is on the local network.
This is probably the easiest answer and depending on the security of the individual VPNs and your VPN credentials the most secure.
Site-to-site VPN
Either using your router or running the VPN software on the Synology system you can join different networks together.
You will need to manage IP address lookup either with /etc/hosts or DNS but all your Synology services become visible and unfortunately are also open to remote compromise if the remote site is hacked or malware/viruses etc attack there.
Port forwarding at the router
Either using the the Dynamic address of the QuickConnect or simply using a Dynamic Address from the local internet router where the Synology is located you can achieve a remote connection.
I would not open Port 22 and forward this to your Synology unless you really desire a miserable existence. Instead I would port forward another higher port on your router to the appropriate port on your Synology. You will also need something like the following
If you use "diskstation.local" as your git address then this would use a Dyndns entry called "easytofindgitserver.dyndns.com" to access it via port 8721. Remember that easytofindgitserver is public information so calling it "myhiddensshtunnel" would be another really bad name.
However using this method would give you a quick and dirty method if you only want to do this for a very short time. Tuning off port forwarding at the router stops this.
On the router Internet Port 8721 would be mapped to the port 22 (e.g. 192.168.0.12 port 22).
I hope this gives you some ideas.