Skip to content

Instantly share code, notes, and snippets.

@ngoviet
Forked from walkerjeffd/Synology-Diskstation-Git.md
Last active August 16, 2021 14:00
Show Gist options
  • Save ngoviet/ff08a7eb9f9da510564d to your computer and use it in GitHub Desktop.
Save ngoviet/ff08a7eb9f9da510564d to your computer and use it in GitHub Desktop.
Cấu hình git server trên Synology Diskstation

Cấu hình NAS Synology thành Git Server

Cho phép SSH

Edit etc/passwd

vi /etc/passwd
  • Người dùng có shell: /sbin/nologin không thể đăng nhập qua SSH
  • Để có thể SSH thay đổi dòng cấu hình user giống với root và admin, thường là /bin/sh
  • Example

Edit row

gituser:x:1026:100::/var/services/homes/gituser:/var/packages/Git/target/bin/git-shell

become

gituser:x:1026:100::/var/services/homes/gituser:/bin/sh

Cấu hình người dùng và thư mục git

  • Tạo người dùng gituser cùng với File Station và WebDAV privilages
  • Thêm thư mục mới git (ở /volume1/git) với quyền read/write cho gituser and admin. Đây là thư mục chứa các repos.
  • Cài đặt gói Git Server
  • Mở Git Server và cấp quyền cho gituser
  • Mở truy cập SSH (Control Panel > Terminal & SNMP > Enable SSH Service)

Configure SSH Access

  • 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 copy public key from local computer to /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
  • Config for gituser can SSH via rsa key
cd /var/services/homes/
chown gituser
chmod 755 gituser

Set Up New Repo on NAS

  • create bare repo as root
ssh [email protected]
cd /volume1/git/
git --bare init <repo-name>.git
chown -R gituser:users <repo-name>.git

Add NAS as Remote for Local Repo

  • Clone repo from NAS
git clone ssh://[email protected]:port/volume1/git/<repo-name>.git

Khởi tạo git trên server

cd /volume1/git
git --bare init <repo-name>.git

Đẩy project có sẵn lên git

git init
git add *
git commit -m "Khoi tao"
git remote add origin ssh://[email protected]:2222/volume1/git/<repo-name>.git
git push origin master

Tạo file .gitignore và cập nhật

type NUL > .gitignore
echo bower_components > .gitignore
echo node_modules >> .gitignore
echo libs >> .gitignore

Xử lý lỗi Cập nhật .gitignore mà tracking vẫn không update

Xóa cache của git

git rm -r --cached .
git add .
git commit -m "fixed untracked files"

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/

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