Skip to content

Instantly share code, notes, and snippets.

@PhilMurwin
Forked from walkerjeffd/Synology-Diskstation-Git.md
Last active October 17, 2019 15:17
Show Gist options
  • Save PhilMurwin/85cb1281541139f3d49809cbdf71ae40 to your computer and use it in GitHub Desktop.
Save PhilMurwin/85cb1281541139f3d49809cbdf71ae40 to your computer and use it in GitHub Desktop.
Instructions for setting up git server on Synology Diskstation

Configure Synology NAS as Git Server

Instructions for setting up a git server on a Synology NAS with Diskstation. Specifically, I am using a DS218+ with DSM 6+.

Set Up User group and Folder

  • Create group gitusers via Diskstation interface (with File Station and WebDAV privilages)
  • Add new shared folder called Git (located at /volume1/Git) with read/write access for group gitusers. This folder will hold all the repos.
    cd /volume1
    mkdir Git
    
  • Set gitusers as the group owner of the Git folder
    cd /volume1
    sudo chown -R root:gitusers Git
    
  • Install Git Server package via Diskstation
  • Open Git Server and allow individual users permissions
  • Enable SSH access on Diskstation (Control Panel > Terminal & SNMP > Enable SSH Service) (recommend changing the port to something other than 22

Make a symbolic link in root (Optional)

  • Create a symbolic link in the root volume pointing to the git folder
ln -s /volume1/Git Git

Configure SSH Access

  • create ~/.ssh folder for gituser on server (where gituser is the target username)
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 rename id_rsa.pub to authorized_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
  • If the server keeps asking for password when pushing/pulling etc
    Apparently this happens because ssh doesn't like when other users can write to the home directory.
chmod 755 /volume1/homes/my-nas-user

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:gitusers <repo-name>.git
chmod -R 775 <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

Add or update a remote's URL

  • Add a remote
    git remote add origin ssh://youruser@diskstation:port/volume1/Git/<repo-name>.git
    -- If you made a symbolic link the remote URL can be shortened somewhat
    git remote add origin ssh://youruser@diskstation:port/Git/<repo-name>.git
    
  • Update a remote url
    git remote set-url origin ssh://youruser@diskstation:port/volume1/Git/<repo-name>.git
    -- If you made a symbolic link the remote URL can be shortened somewhat
    git remote set-url origin ssh://youruser@diskstation:port/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://web.archive.org/web/20140316155151/http://www.heidilux.com/2014/02/setup-git-server-synology-nas/
https://forum.synology.com/enu/viewtopic.php?t=76585
https://blog.aaronlenoir.com/2018/05/06/ssh-into-synology-nas-with-ssh-key/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment