1.首先安装git,使用yum在线安装git
[root@localhost ~]# yum install -y git [root@localhost ~]# git --version git version 1.7.1
2.建立一个git用户,来运行git服务vim
[root@localhost home]#adduser git 服务器
或者能够使用ssh
[root@localhost home]# useradd git
[root@localhost home]# passwd gitrest
3.建立空仓库code
cd /home/git mkdir project.git cd project.git git init --bare cd .. chown -R git:git project.git/
4.在服务器端开RSA认证it
vim /etc/ssh/sshd_config
修改如下三个选项并重启io
RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys 重启命令-> systemctl restart sshd.service
这里咱们所知的是.ssh/authorized_keys这个是公钥存储的地方,是在/home/git/下的.ssh/下存放,实际目录/home/git/.ssh/authorized_keys。若是须要免密登陆,须要将本身客户端的id_rsa.pub公钥填写进去改文件(一行一个),若是该文件不存在则自行建立 而且修改权限 为600 例:如个人用户为git来管理git服务器 则还须要将 该文件的拥有者和群组修改 chown git:git authorized_keys登录
5.客户端clone服务器端
格式:git clone 用户名@xxx.xxx.xx.xx:/home/git/初始化仓库目录文件 例子:git clone git@192.168.0.109:/home/git/project.git
若是须要免密登陆则看上栏配置,与ssh创建信任
总结:免密登陆是个坑,多半免密登陆不了的都是权限没有调整好或没开启RSA认证,仅以此文件避免往后踩坑