git 简单服务搭建

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值