以前本身是按照 Git 服务器搭建这篇博客来安装git服务器的,一步步顺序下来,但git clone的时候,每次都要求输入密码。说好的SSH免密登陆呢。先后搞了一天多才搞定,如今记录下踩过的坑。html
那篇文章的原文:git
收集全部须要登陆的用户的公钥,公钥位于id_rsa.pub文件中,把咱们的公钥导入到/home/git/.ssh/authorized_keys文件里,一行一个。 若是没有该文件建立它: $ cd /home/git/ $ mkdir .ssh $ chmod 700 .ssh $ touch .ssh/authorized_keys $ chmod 600 .ssh/authorized_keys
这边建立的文件夹,应该受权给git用户,因此应该再加一句:shell
$ chown -R git:git .ssh
那篇文章没有提修改/etc/ssh/sshd_config下的配置文件。bash
在Git服务器上首先须要将/etc/ssh/sshd_config中将RSA认证打开,即: 1.RSAAuthentication yes 2.PubkeyAuthentication yes 3.AuthorizedKeysFile .ssh/authorized_keys
修改配置以后,须要重启sshd服务器
systemctl restart sshd.service
能够经过这个命令去测试SSH是否可链接:ssh
ssh -T git@192.168.1.85
而后在服务器,能够经过这个命令查看ssh状态测试
systemctl status sshd.service
ssh能够链接了,但git clone的时候,报spa
fatal: protocol error: bad line length character: This
找到/etc/passwd,原文里面是说:rest
这样咱们的 Git 服务器安装就完成了,接下来咱们能够禁用 git 用户经过shell登陆,能够经过编辑/etc/passwd文件完成。找到相似下面的一行: git:x:503:503::/home/git:/bin/bash 改成: git:x:503:503::/home/git:/sbin/nologin
但就是这个nologin让咱们报错了,应该改为:code
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
附Git建立仓库命令:
git init --bare demo.git
--将建立的库受权给git用户
/home/gitrepo/demo.git/ chown -R git:git demo.git