- 安装git
# yum install -y git
- 查看git版本号
# git --version
git version 1.8.3.1
- 创建git用户用于管理
# useradd git
# passwd git
- 创建git目录和一个git裸仓
# cd /
# mkdir git
# cd git
# git init --bare test.git
# chown -R git:git test.git
[root@localhost test.git]# ls -la
total 12
drwxr-xr-x. 7 git git 119 Oct 6 22:46 .
drwxr-xr-x. 3 root root 22 Oct 6 22:46 ..
drwxr-xr-x. 2 git git 6 Oct 6 22:46 branches
-rw-r--r--. 1 git git 66 Oct 6 22:46 config
-rw-r--r--. 1 git git 73 Oct 6 22:46 description
-rw-r--r--. 1 git git 23 Oct 6 22:46 HEAD
drwxr-xr-x. 2 git git 242 Oct 6 22:46 hooks
drwxr-xr-x. 2 git git 21 Oct 6 22:46 info
drwxr-xr-x. 4 git git 30 Oct 6 22:46 objects
drwxr-xr-x. 4 git git 31 Oct 6 22:46 refs
- 开启git服务器RSA认证
# vim /etc/ssh/sshd_config
1.RSAAuthentication yes
2.PubkeyAuthentication yes
3.AuthorizedKeysFile .ssh/authorized_keys
- 在git服务器~/.ssh/authorized_keys内增加客户端公钥
- 客户端创建Ssh Key
$ ssh-keygen -t rsa -C "youremail@example.com"
8.将新生成的公钥(id_rsa.pub)内容粘贴到服务端的authorized_keys内
$ pwd
/Users/panzhijie/.ssh
$ ls
id_rsa id_rsa.pub known_hosts
- 克隆测试
$ git clone git@172.16.1.4:/git/panzhijie.git
Cloning into 'panzhijie'...
warning: You appear to have cloned an empty repository.
$ ls
panzhijie
- 服务端禁用git登录
# vim /etc/passwd
git:x:1000:1000::/home/git:/usr/bin/git-shell
网友评论