git 服务端安装

服务器端创建 git 用户,用来管理 Git 服务,并为 git 用户设置密码

[root@localhost home]# id git
id: git:无此用户
[root@localhost home]# useradd git
[root@localhost home]# passwd git

 

设置 /home/data/git/gittest.git 为 Git 仓库
然后把 Git 仓库的 owner 修改为 git

[root@localhost home]# mkdir -p data/git/gittest.git
[root@localhost home]# git init --bare data/git/gittest.git
Initialized empty Git repository in /home/data/git/gittest.git/
[root@localhost home]# cd data/git/
[root@localhost git]# chown -R git:git gittest.git/

  

禁用shell登录:
出于安全考虑,第二步创建的git用户不允许登录shell,这可以通过编辑/etc/passwd文件完成。找到类似下面的一行:
git:x:1001:1001:,,,:/home/git:/bin/bash
改为:
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell


git clone、push 提示输入密码但输入后登录被拒绝
客户端创建 SSH 公钥和私钥
$ ssh-keygen -t rsa -C "[email protected]"
由 AuthorizedKeysFile 得知公钥的存放路径是 .ssh/authorized_keys,实际上是 $Home/.ssh/authorized_keys,由于管理 Git 服务的用户是 git,所以实际存放公钥的路径是 /home/git/.ssh/authorized_keys
在 /home/git/ 下创建目录 .ssh

把专用密钥(private and public keys)添加到 ssh-agent 的高速缓存中
ssh-add ~/.ssh/id_dsa
ssh-add -d ~/.ssh/id_xxx.pub
如果执行ssh-add时提示”Could not open a connection to your authentication agent”,可以现执行命令:
ssh-agent bash
然后再执行上述 ssh-add 操作
然后可以进行clone等操作了

push 出错的解决 (branch is currently checked out)
是由于git默认拒绝了push操作,需要进行设置,修改.git/config文件后面添加如下代码:
[receive]
denyCurrentBranch = ignore

猜你喜欢

转载自www.cnblogs.com/lauhp/p/9486517.html