1,安装git
AB设备
yum install git -y
git --version #检查安装情况
2,A设备
创建用户git,并登陆
[root@135 ~]# useradd git -d /home/git -m -s /bin/bash
[root@135 ~]# su git
创建sample库
[root@135 ~]$ cd ~
[root@135 ~]# git init --bare sample.git
3,设置SSH Key
收集客户端B的公钥,复制到服务器A上
B设备生成公私钥
[root@136 ~]##ssh-keygen -t rsa -b 4096
Enter file in which to save the key (/root/.ssh/id_rsa):直接回车
Enter passphrase (empty for no passphrase): 输入用户密码,一般直接回车
生成私钥/root/.ssh/id_rsa,公钥/root/.ssh/id_rsa.pub
A服务器/etc/ssh/sshd_config文件打开一下配置
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
保存并重启 sshd 服务:
[root@135 ~]# /etc/rc.d/init.d/sshd restart
拷贝B设备的公钥/root/.ssh/id_rsa.pub到A服务器的
[root@136 ~]#scp /root/.ssh/id_rsa.pub root@192.168.213.135:/home/git/.ssh/
[root@135 ~]#cat /home/git/.ssh/id_rsa.pub > /home/git/.ssh/authorized_keys
并且root权限修改/home/git/.ssh的owner
[root@135 ~]# mkdir -p /home/git/.ssh
[root@135 ~]# chown -R git:git /home/git/.ssh
[root@135 ~]# chmod 700 /home/git/.ssh
[root@135 ~]# chmod 600 /home/git/.ssh/authorized_keys
4,客户端B获取Sample库
[root@136 ~]#git clone git@192.168.213.135:/home/git/sample.git
Initialized empty Git repository in /root/sample/.git/
warning: You appear to have cloned an empty repository.
5,使用
客户端B上/home/git/中写一些内容
[root@136 ~]# touch Readme
[root@136 ~]#git add .
[root@136 ~]# git config --global user.name "git"
[root@136 ~]#git commit -am "add member mender"
[root@136 ~]#git push