Robin Rottier
Robin Rottier's Blog


Robin Rottier's Blog


Synology DSM - host your own GIT server

Robin Rottier's photo
Robin Rottier
·Jan 7, 2021·

8 min read

Use your Synology to host Gitea under Docker and run your own GIT server.

Why host your own? Because you can have local performance and unlimited private repositories. Or you simply want to keep your stuff hosted on your server and under your control.

This example is on Gitea, but other GIT server deployments are available of course - as installs directly onto your Synolgoy DSM (or any Linux server), and more easily as their own Docker images.

Why Gitea? The main reason is that it is easy and it has very low minimal requirements so is suitable for a low spec server such as a NAS. Also, it does just work.

Setup as follows:

  1. From the Docker app on your Synology in Registry find gitea/gitea and download the image (105Mb)
  2. On the image tab select that download and click launch to create a new container.
  3. Under Advanced settings select the following:

    1. Enable auto-restart
    2. Under Volume create a new folder on your NAS (probably somewhere under /volume1) and have it mounted as /data
    3. Under Port Settings map some local port (I chose 3022) to port 22 in the container (for ssl) and local port 3000 to container port 3000 for main website browsing. Choose other local ports if those already taken.
    4. Under environment you should see GITEA_CUSTOM already set to /data/gitea where it will store all its stuff -- hence the need to provide that file mapping to a directory on your main Synology volume.
  4. The instance is now running and you should see it listed under Container tab. Double click to bring up the container properties dialog - not much to see or do here but it shows its running. The terminal tab will do nothing as Gitea doesn't support a ssh terminal.

  5. You can browse to the running Gitea with something like nas.local:3000 i.e. browing to port 3000 on your NAS at nas.local and then port reditected 3000 to 3000 for web browsing.
  6. Go through the setup options -- give your site a title but I leave everything much as the default. The last setup option is for an admin account, but it says 'Creating an administrator account is optional. The first registered user will automatically become an administrator.' so leave it blank.
  7. Click the Install Gitea button and wait
  8. After the setup the page refreshes to http://localhost:3000/user/login but that only make sense if you were on the hosting server itself. Instead change the url you the redirected port on your NAS, in my example http://nas.local:3002
  9. You should now see the Sign In page to register the first user, who will become admin also. Use your enail address
  10. After setup, you should see a Gitea welcome page until you've created your first repository - then it starts to look and feel a bit like Github

You will still need to get ssh working in order to use Git from your development workstation using the git: syntax for repos access. The steps for ssh access to the Synology in summary:

  1. Create your own key pair and save the public key in the settings of your account on the Gitea profile admin (which will write it to the .ssh/authorized_keys file on the Gitea server).
  2. Save the private key (and you keep this bit secret of course) in your .ssh/config folder - typically as the file id_rsa if that's the sort of key you created.
  3. I also like to use the .ssh/config file to create a alias especially if port if not the standard for ssh. For this scenario, accessing Gitea setup as above, we'll have something like:
    Host git.nas
    HostName nas.local
    Port 3022
    User git
    Where git.nas is the alias name I want to use, naslocal is the actual hostname for the Synology running Docker running Gitea - or it could be your NAS IP address of course - and 3022 is the port redirection we specified in the container setup mapping to port 22 on the running instance.

You can then test this using ssh git.nas . It wont work by giving you a shell prompt BUT it will give a message indicating all the ssh stuff is ok and you connected:

PS C:\Users\yourname> ssh git.nas
PTY allocation request failed on channel 0
Hi there, yourname! You've successfully authenticated with the key named yourname@DESKTOP-1234, but Gitea does not provide shell access.
If this is unexpected, please log in with password and setup Gitea under another user.
Connection to nas.local closed.

NOW you are ready to create your first repos on your GIT server.

On the Gitea website dashboard, log in and click "+" to create a repository. Things tend to just work better if you create a empty repository on the server first - Gitea gives you handy options for a .gitignore and a licence file. Go to your local workstation, cd to the repository root directory and clone it...

PS C:\Users\yourname\source\repos\test1> git clone git@git.nas:yourname/test1.git

If you want to start with a local repository and just push it, then on your dev workstation, in a command prompt, cd to the directory you want to upload and create a local GIT repos (or of course, use one you prepared earlier)

PS C:\Users\yourname\source\repos\test1> git init
PS C:\Users\yourname\source\repos\test1> git add .
PS C:\Users\yourname\source\repos\test1> git commit -m "Initial Commit"

PS C:\Users\yourname\source\repos\test1> git remote add origin git@git.nas:yourname/test1.git
PS C:\Users\yourname\source\repos\test1> git push --set-upstream origin master
Share this