Skip to content

Instantly share code, notes, and snippets.

@hqingyi
Last active October 23, 2015 08:05
Show Gist options
  • Save hqingyi/3286ada52af5da5f7d66 to your computer and use it in GitHub Desktop.
Save hqingyi/3286ada52af5da5f7d66 to your computer and use it in GitHub Desktop.
使用ssh搭建简易私有的git服务器

准备

相关服务

apt-get install git

用户配置

adduser --shell /usr/bin/git-shell git

扩展阅读: What's the difference between adduser and useradd?

如何配置权限

把客户端~/.ssh/id_rsa.pub内容添加到服务器~git/.ssh/authorized_keys中就可以了。

扩展阅读:Providing Your SSH KEY

使用

服务器初始化仓库

# 替换${name}为你的仓库名
cd ~git && sudo -u git git init --bare ${name}.git

客户端绑定远程仓库并推送

# 绑定远程仓库
git remote add origin git@${host}:${name}.git
# push
git push --set-upstream origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment