centos6.9搭建git1.7.1

  第一步,安装git:

  在root下创建git用户,设置密码:

[root@VM-0-14-centos ~]# useradd git
[root@VM-0-14-centos ~]# passwd git

  给git用户设置sudo权限:

[root@VM-0-14-centos ~]# vi /etc/sudoers

  找到这一行:

root    ALL=(ALL)       ALL

  在下面加这一行:

git     ALL=(ALL)       ALL

  切换到git用户下执行安装git操作:

[root@VM-0-14-centos ~]# su - git
[git@VM-0-14-centos ~]$ sudo yum install -y git
Package git-1.7.1-10.el6_10.i686 already installed and latest version

  原来之前我装过了,确认下git版本:

[root@VM-0-14-centos ~]# git --version
git version 1.7.1

  进入第二步,创建github的登陆用户的证书文件:

[git@VM-0-14-centos ~]$ mkdir .ssh
[git@VM-0-14-centos ~]$ chmod 755 .ssh
[git@VM-0-14-centos ~]$ touch .ssh/authorized_keys
[git@VM-0-14-centos ~]$ chmod 644 .ssh/authorized_keys 

  后面如果想给相关人员使用,就要把他们的公钥导入到这个文件里。公钥可以去你的C盘用户你的具体用户名,如Administrator.sshid_rsa.pub中查看。如果没有就自己生成一个。怎么生成?执行以下命令,输入你的邮箱:

[git@VM-0-14-centos ~]$ ssh -keygen -t rsa -C '你的邮箱'

  一步步回车下来,最后得到的id_rsa.pub中的内容就是公钥

cat ~/.ssh/id_rsa.pub

  好了,现在可以开始用了,第三步,初始化一个github仓库:  

[git@VM-0-14-centos ~]$ mkdir repository
[git@VM-0-14-centos ~]$ cd repository/
[git@VM-0-14-centos repository]$ git init spring-cloud-gateway.git
Initialized empty Git repository in /home/git/repository/spring-cloud-gateway.git/.git/

  win10本机使用git-bash克隆到E盘workspace目录下:

wulf@wulf00 MINGW64 /e/workspace/开源
$ git clone ssh://git@111.11.11.11:11/home/git/repository/spring-cloud-gateway.git
Cloning into 'spring-cloud-gateway'...
git@111.11.11.11's password:
warning: You appear to have cloned an empty repository.

  这里因为我的ssh默认端口不是22,所以需要指定一下。完。

原文地址:https://www.cnblogs.com/wuxun1997/p/13837963.html