Git server on Synology NAS: installation and configurations
The following guide show how to install, configure and use a Git server on Synology NAS. It is tested on Synology DS115j with DSM 5.1.
1. Installing Git Server
From the DSM’s dashboard (as admin/root user) install and configure the Git Server package:
- Go on the Package Center and install the Git Server package.
- Enable SSH Service from Control Panel > Terminal & SNMP.
- Enable user’s home directory from Control Panel > User > Advanced.
- Create one or more users that will use Git from their local PC and add them in the
administrators
group from Control Panel > User > Edit. - Allow users to use Git from Main Menu > Git Server.
Create the Git directory
Create a new directory named git
, inside /volumes1
, that will contains all your Git’s repositories:
$ # Login via SSH on Synology NAS
$ ssh root@[syn-ip-addr]
$
$ # Create the directory
$ mkdir /volumes1/git
$ chown -R admin:administrators git
$ chmod -R 772 git
Where:
-
[syn_ip_addr]
is the Synology’s IP LAN address (e.g. 192.168.1.1).
NOTE: you should use the root user and not the admin user in order to have full read/write permissions on the server. The root’s password is the same of admin’s password.
2. Creating a new shared repository on the server
A shared repository will be used to keep a centralized copy of the git repo. All users working on the repo will get a clone on their local PC and will get/send changes with pull
/push
git commands.
The following command creates a new shared git repository on the server (your Synology NAS):
$ ssh admin@[syn-ip-addr]
$ cd /volumes1/git
$ git init --bare --shared [my-project].git
Where:
[my-project]
is the repository name.[syn-ip-addr]
is the Synology’s IP address.
See here for more informations about git shared repositories.
3. Use the repository on your local PC
Finally, a user can clone an existing repository on his/her local PC, or can connect an existing local repo to one shared on the Git server.
Cloning a repository
Use this command to get the shared repository on your local PC:
$ git clone ssh://[git-user]@[syn-ip-addr]/volume1/git/[my-project].git
Where:
[git-user]
is the git user (e.g.netgloo
).[syn-ip-addr]
is the Synology’s IP address.[my-project]
is the repository name.
NOTE: will be created a new folder [my-project] on your PC.
Connect an existing local repository with the server
Instead of cloning an empty repository, it may be that you already have a local project and want to connect it with the server.
You can do it in this way (from your PC):
$ cd [project-folder]
$
$ # Create the Git repository (if there is not already one)
$ git init
$
$ # Add the server's URL
$ git remote add origin ssh://[git-user]@[syn-ip-addr]/volume1/git/[my-project].git
$
$ # Make the first commit and push the project on the server
$ git add --all
$ git commit -a -m "Initial commit message"
$ git push -u origin master
Useful Tips
1) Commit without password
Follow this procedure to make commits without insert your password, using public key authentication.
Generate a key pair on your PC with the following command if you don’t already have one:
$ # Check if you already have an SSH key on your PC with:
$ ll ~/.ssh/id_rsa.pub
$ # If you don't have a public key, generate it with:
$ ssh-keygen -t rsa
$ # Then type
$ ssh-add
Copy the public key in the home of your user in the Synology server (the user you want to use with Git):
$ # Copy the key on the server
$ scp /home/[your-pc-user]/.ssh/id_rsa.pub root@[syn-ip-addr]:/volume1/homes/[git-user]/
$
$ # Access the server via ssh and put the key inside .ssh directory
$ ssh root@[syn-ip-addr]
$ cd /volume1/homes/[git-user]
$ mkdir .ssh
$ mv id_rsa.pub .ssh/authorized_keys
$
$ # Set right owner and permissions
$ chown -R [git-user]:users .ssh
$ chmod 700 .ssh
$ chmod 644 .ssh/authorized_keys
Repeat the above steps for each user you want to enable to Git, generating a personal key pair for each of them.
Enable the key based authentication on the server:
$ ssh root@[syn-ip-addr]
$ vi /etc/ssh/sshd_config
Decomment the following lines:
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
Reboot the system, then try to clone a Git repository from the server through your git user:
$ git clone ssh://[git-user]@[syn-ip-addr]/volume1/git/[my-project].git
It should works without asking you the password.
Troubleshooting: if the authentication without password doesn’t works
Try with the following steps on the Synology server.
$ # Login via SSH on Synology NAS
$ ssh root@[syn-ip-addr]
1. Change permissions for the user’s home:
$ chmod 755 [user-home]
2. Change the user’s shell:
$ vi /etc/passwd
on the row of git user change last part to:
:/bin/ash
3. Reboot the Synology
4. Try to access the server without the password, e.g. trying a git clone
or git push
: now it should works!
5. If it works, you can try to restore user’s home permissions and the user’s shell.
2) Set an existing repository as shared
A repository needs to be shared if more than one user is working on the repo itself, so all users belonging to the same group (e.g. the group administrators) can send changes on the repo.
If you created a repo as no shared, following commands, executed on the server, allow to make shared an existing repository:
$ cd [my-project].git
$ git config core.sharedRepository group
$ chgrp -R administrators .
$ chmod -R g+w .
$ chmod g-w objects/pack/*
$ chmod g+s `find . -type d`
Where administrators
is the group name and [my-project].git
the repository directory.
See here for more details.
Commons Git commands
See this other post for more commons git commands.
References
http://forum.synology.com/enu/viewtopic.php?t=73064
http://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server
http://stackoverflow.com/questions/20074692/set-up-git-on-a-nas-with-synologys-official-package
http://blog.osdev.org/git/2014/02/13/using-git-on-a-synology-nas.html
https://www.atlassian.com/git/tutorials/
http://stackoverflow.com/questions/2432764/change-the-uri-url-for-a-remote-git-repository
-
Niklas
-
Andrea
-
-
Frank
-
Andrea
-
-
Alessandro Candini
-
Lori
-
Dani
-