linux 下搭建git,Linux 下搭建git 服务器(示例代码)

环境: 服务器 centos7.3 +git1.8.3.1

客户端 centos7.2 +git1.8.3.1

服务器配置;

1.安装git yum install git -y

2.创建git用户

[[email protected] ~]# id git

id: git: no such user

[[email protected] ~]# useradd git

[[email protected] ~]# id git

uid=1001(git) gid=1001(git) groups=1001(git)

为了安全起见,可以只允许git使用git命令

sed -i ‘/^git/s#/bin/bash#/usr/bin/git-shell#g‘ /etc/passwd

3.在服务端创建git仓库

把/data/git/test.git设置为GIT仓库,并修改属主属组为git

[[email protected] ~]# mkdir -p /data/git/test.git

[[email protected] ~]# git init --bare /data/git/test.git #--bare参数创建目录结构

Initialized empty Git repository in /data/git/test.git/

[[email protected] ~]# chown -R git.git /data/git/test.git

[[email protected] ~]# cd /data/git/test.git/

[[email protected] test.git]# ll

total 12

drwxr-xr-x. 2 git git 6 Jun 28 22:57 branches

-rw-r--r--. 1 root root 66 Jun 28 22:58 config

-rw-r--r--. 1 git git 73 Jun 28 22:57 description

-rw-r--r--. 1 git git 23 Jun 28 22:57 HEAD

drwxr-xr-x. 2 git git 242 Jun 28 22:57 hooks

drwxr-xr-x. 2 git git 21 Jun 28 22:57 info

drwxr-xr-x. 4 git git 30 Jun 28 22:57 objects

drwxr-xr-x. 4 git git 31 Jun 28 22:57 refs

客户端配置:

1.安装git yum install git -y

2.配置免密钥登录

[[email protected] ~]#ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

ac:be:d1:12:37:89:1b:ca:52:8b:4c:b7:97:38:18:41 [email protected]

The key‘s randomart image is:

+--[ RSA 2048]----+

|   E                      |

|  .                        |

|   .                       |

|    .    o .              |

|   o o + S            |

|   o B = O .         |

|     = B B .          |

|       . + o            |

|         o.              |

+--------------------+

[[email protected] ~]# ssh-copy-id 192.168.138.133

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

[email protected]‘s password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh ‘192.168.138.133‘"

and check to make sure that only the key(s) you wanted were added.

3.创建本地仓库

[[email protected] ~]# mkdir /git

[[email protected] ~]# cd /git/

[[email protected] git]# ll

total 0

[[email protected] git]# git clone 192.168.138.133:/data/git/test.git/

Cloning into ‘test‘...

warning: You appear to have cloned an empty repository.

[[email protected] git]# ll

total 0

drwxr-xr-x. 3 root root 17 Jul 3 20:42 test

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值