1,检测系统中git的版本(版本很低)
yum info git
2,git最新源码下载地址
https://github.com/git/git/releases
https://www.kernel.org/pub/software/scm/git/
3,下载最新的git
wget -P /opt/ https://www.kernel.org/pub/software/scm/git/git-2.14.1.tar.gz
4,解压
tar xzvf git-2.14.1.tar.gz
5,指定安装目录
./configure --prefix=/usr/local/git
6,安装依赖lib
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum install gcc perl-ExtUtils-MakeMaker
7,编译安装
make && make install
8,配置环境变量
#git settings
GIT_HOME=/usr/local/git
export PATH=$JAVA_HOME/bin:$GIT_HOME/bin:$PATH
9,配置生效
source /etc/profile
10,检查git是否安装成功
git --version
11,创建git账户,密码也为git
useradd git
passwd git
12,使用git登录并进入git目录
su - git
cd ~
13,在/home/git目录下创建.ssh目录,并进入
mkdir .ssh && cd .ssh
14,创建一个存储所有登录用户的公钥(id_rsa.pub),一行一个用户
touch authorized_keys
15,初始化git仓库
mkdir /var/git && cd /var/git
git init --bare empty.git
chown -R git:git empty.git
16,禁用shell
vi /etc/passwd
git:x:1000:1000::/home/git:/usr/bin/git-shell
https://github.com/git-for-windows/git/releases/download/v2.14.1.windows.1/Git-2.14.1-64-bit.exe
18,打开git bash,直接输出命令生成公钥
ssh-keygen -t rsa -C "lcj@test.com"
19,将C:\Users\Administrator.ssh\id_rsa.pub文件内容写入到git服务器,用来验证
cat id_rsa.lcj.pub >> /home/git/.ssh/authorized_keys
20,使用idea或gitbash从git服务器上clone项目
git clone git@ip:/var/git/emtpy.git
21,设置个人信息
git config [--global] user.email 'lcj@test.com'
git config [--global] user.name 'lcj'
22,一些问题及其解决方法
加权限
chown -R git:git .ssh
修改配置,启用ssh公钥认证
vi /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
systemctl restart sshd
原文链接:https://www.f2er.com/centos/376195.html