@lniwn
2017-09-18T18:56:56.000000Z
字数 1190
阅读 791
Linux
创建一个单独的用户用于git提交
1) 新建用户
adduser -d /home/gitmanager -m gitmanager
adduser为perl命令,使用简单;useradd为shell命令
2) 修改密码
passwd gitmanager
如果想修改用户的根目录,可以使用usermod命令
usermod -m -d /newhome/gitmanager gitmanager
为了安全起见,禁止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
目录,解决方法如下:
cp /usr/share/doc/git/contrib/git-shell-commands/ /home/gitmanager/ -R
chown gitmanager:gitmanager /home/gitmanager/git-shell-commands/ -R
chmod +x /home/gitmanager/git-shell-commands/help
chmod +x /home/gitmanager/git-shell-commands/list
1) 使用puttygen.exe生成key
复制红色方框内的ssh-rsa到authorized_keys文件
2) 上传authorized_keys到服务器/home/gitmanager/.ssh/authorized_keys
cd /home/gitmanager
mkdir repo # 创建仓库目录
cd repo
git init --bare project.git # 初始化仓库
chown -R gitmanager:gitmanager /home/gitmanager/ # 修改目录权限
通过ls -l
命令确认当前目录所有内容均属于gitmanager
gitmanager@oaoa.me:~/repo/dmwebkit.git
使用你的服务器ip或者域名替换"oaoa.me"