git安装配置

Posted hellowcf

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了git安装配置相关的知识,希望对你有一定的参考价值。

1,  安装git依赖

sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker

2,  下载git并解压

Tar –xvf XXX

3, 将其安装在“/usr/local/git”目录下,命令如下:

make prefix=/usr/local/git all

sudo make prefix=/usr/local/git install

4,  配置git

在etc/profile中的最后面添加

export PATH=/usr/local/git/bin:$PATH

然后启动生效profile

Source /etc/profile

5,检查是否安装成功

Git –version

在服务器创建git仓库

设置/home/git/gittest.git为仓库

在/home/git目录下创建gittest.git

Mkdir gittest.git

初始化仓库

Git init –bare gittest.git

添加ssh公钥,在/home/git/.ssh/authorized_keys里添加客户端的公钥,一行一个。

如果没有文件,可以新建

mkdir /home/git/.ssh

touch /home/git/.ssh/authorized_keys

客户端生成密钥,使用ssh-keygen –t rsa生成

在跟目录下有.ssh文件,文件中会有两个文件

Id_rsa为私钥

Id_rsa.pub为公钥

将客户端的公钥copy到服务器的authorized_keys中即可

测试,可以使用

Git clone [email protected]:/home/git/gittest.git

如果提示

正克隆到 ‘gittest‘...

ssh: connect to host localhost port 22: Connection refused

fatal: 无法读取远程仓库。

 

请确认您有正确的访问权限并且仓库存在。

说明服务端的ssh没有启动

/etc/rc.d/init.d/sshd start

在启动之前打开服务端的rsa认证

进入 /etc/ssh 目录,编辑 sshd_config,打开以下三个配置的注释

RSAAuthentication yes

PubkeyAuthentication yes

AuthorizedKeysFile .ssh/authorized_keys

由 AuthorizedKeysFile 得知公钥的存放路径是 .ssh/authorized_keys,实际上是 $Home/.ssh/authorized_keys,由于管理 Git 服务的用户是 git,所以实际存放公钥的路径是 /home/git/.ssh/authorized_keys

重启sshd服务

以上是关于git安装配置的主要内容,如果未能解决你的问题,请参考以下文章

macOS:安装配置Git

macOS:安装配置Git

centos安装配置git配置颜色git命令tab补全配置

git安装并与远程仓库关联相关配置

如何在Visual Studio中配置git

git---安装及配置