[关闭]
@lniwn 2017-09-18T18:56:56.000000Z 字数 1190 阅读 791

在Ubuntu 16.14上搭建Git Server

Linux


1.新建Git用户

创建一个单独的用户用于git提交
1) 新建用户
adduser -d /home/gitmanager -m gitmanager
adduser为perl命令,使用简单;useradd为shell命令
2) 修改密码
passwd gitmanager

如果想修改用户的根目录,可以使用usermod命令
usermod -m -d /newhome/gitmanager gitmanager

2.禁止Git用户使用shell登录

为了安全起见,禁止gitmanager用户使用shell登录,原理就是修改gitmanager的登录shell为git-shell
1) 确认git-shell路径
which git-shell
2) 修改登录shell
usermod -s /usr/bin/git-shell gitmanager
3) Interactive git shell is not enabled
此时,如果直接su gitmanager切换用户,会出现错误:

fatal: Interactive git shell is not enabled.
hint: ~/git-shell-commands should exist and have read and execute access.

原因是找不到git-shell-commands目录,解决方法如下:

  1. cp /usr/share/doc/git/contrib/git-shell-commands/ /home/gitmanager/ -R
  2. chown gitmanager:gitmanager /home/gitmanager/git-shell-commands/ -R
  3. chmod +x /home/gitmanager/git-shell-commands/help
  4. chmod +x /home/gitmanager/git-shell-commands/list

image_1bqa9siht1mv18ac16cjvm0ppe13.png-6.2kB

3.配置ssh密钥

1) 使用puttygen.exe生成key
image_1bqa943kat0a1djp17f925v9s49.png-32.7kB
复制红色方框内的ssh-rsa到authorized_keys文件
2) 上传authorized_keys到服务器/home/gitmanager/.ssh/authorized_keys

4.建立仓库

  1. cd /home/gitmanager
  2. mkdir repo # 创建仓库目录
  3. cd repo
  4. git init --bare project.git # 初始化仓库
  5. chown -R gitmanager:gitmanager /home/gitmanager/ # 修改目录权限

通过ls -l命令确认当前目录所有内容均属于gitmanager

5.克隆远程仓库

gitmanager@oaoa.me:~/repo/dmwebkit.git
使用你的服务器ip或者域名替换"oaoa.me"
image_1bqa9l78q1o8h1lr0jsph7utbom.png-27.4kB

6.参考页面

搭建Git服务器
服务器上的-Git-在服务器上搭建-Git

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注