Centos 搭建git服务器和免密操做

环境说明git

  • CentOS 7.x 最小安装

安装Git

$ yum install git

建立一个git用户组和用户,用来运行git服务shell

$ groupadd git
$ adduser git -g git

禁止git用户登陆: 修改/etc/passwd文件bash

git:x:1000:1000::/home/git:/bin/bash
后面改成:
git:x:1000:1000::/home/git:/bin/git-shell

建立证书登陆

$ mkdir /home/git/.ssh
$ chmod 700 /home/git/.ssh
$ touch 700 /home/git/.ssh/authorized_keys
$ chmod 600 /home/git/.ssh/authorized_keys
$ chown -R git:git /home/git/.

客户机建立ssh密钥:服务器

$ ssh-keygen -t rsa -C "youremail@example.com"

编辑/home/git/.ssh/authorized_keys,把客户端的公钥放进去ssh

初始化Git仓库

$ cd /srv
$ mkdir gitrepo
$ chown -R git:git gitrepo/
$ cd gitrepo

建立一个空的Git仓库,服务器上的Git仓库一般都以.git结尾.net

$ git init --bare firstproject.git

将仓库所属用户改成gitcode

$ chown -R git:git project.git

克隆仓库

在客户机上,安装git,而且运行下面的命令:blog

$ git clone git@xx.xx.xx.xx:/srv/gitrepo/firstproject.git

参考资料 http://www.javashuo.com/article/p-nmuisdtl-ks.htmlrem

相关文章
相关标签/搜索