Nas Git Server

Git User 与 Git Server

创建 Git 仓库目录

创建共享文件夹git-repos

创建 Git 用户

创建用户,用户名gituser,权限设置可访问git-repos目录。

安装 Git Server

在套件中心安装 Git Server,勾选允许gituser访问。

免密 SSH 连接

# 开启免密验证
sudo vi /etc/ssh/sshd_config

# 在 sshd_config 中启用这三项
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
# 在用户目录内创建 .ssh 目录和 authorized_keys 文件
cd /var/services/homes/gituser
mkdir .ssh
# 在 authorized_keys 文件中添加本机 id_rsa.pub 内容
vi .ssh/authorized_keys

# 修改用户目录权限
chmod 775 /var
chmod 775 /var/services
chmod 755 -R /var/services/homes/gituser

其他需要 SSH 免密连接的账户都可以用该方法添加。

创建与访问仓库

# 创建并初始化仓库目录
cd /volume1/git-repos
mkdir test.git
git init --bare test.git

# 设置目录所属和权限
sudo chown -R gituser:users test.git
# sudo chmod -R 770 test.git

# 本地使用命令行测试能否拉取仓库
git clone ssh://gituser@[nas-host]:[ssh-port]/volume1/git-repos/test.git

至此已全部完成,也可以使用 GitHub Desktop 等第三方工具连接 Git 仓库了。

Copyright © 2025 LOLO