Centos 7 搭建Git及安装使用

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

1、查看是否安装了git

rpm -qa|grep git
[root@hp-hp summergao]# yum –y install git
Loaded plugins: fastestmirror, langpacks
[root@hp-hp summergao]# rpm -qa|grep git
lm_sensors-libs-3.4.0-6.20160601gitf9185e5.el7.x86_64
hyperv-daemons-0-0.34.20180415git.el7.x86_64
hypervvssd-0-0.34.20180415git.el7.x86_64
libglvnd-egl-1.0.1-0.8.git5baa1e5.el7.x86_64
hypervkvpd-0-0.34.20180415git.el7.x86_64
libglvnd-glx-1.0.1-0.8.git5baa1e5.el7.x86_64
hyperv-daemons-license-0-0.34.20180415git.el7.noarch
python-dns-1.12.0-4.20150617git465785f.el7.noarch
libglvnd-gles-1.0.1-0.8.git5baa1e5.el7.x86_64
lldpad-1.0.1-3.git036e314.el7.x86_64
ipxe-roms-qemu-20170123-1.git4e85b27.el7_4.1.noarch
hypervfcopyd-0-0.34.20180415git.el7.x86_64
xdg-utils-1.1.0-0.17.20120809git.el7.noarch
net-tools-2.0-0.24.20131004git.el7.x86_64
linux-firmware-20180911-69.git85c5d90.el7.noarch
numad-0.5-18.20150602git.el7.x86_64
taglib-1.8-7.20130218git.el7.x86_64
lockdev-1.0.4-0.13.20111007git.el7.x86_64
libglvnd-1.0.1-0.8.git5baa1e5.el7.x86_64
crontabs-1.11-6.20121102git.el7.noarch

 以上内容说明没有安装

若已经安装,需要先卸载。卸载命令如下:

rpm -e --nodeps git  或者  rpm -e git

2、安装git

yum -y install git
[root@hp-hp summergao]# yum install git
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirror01.idc.hinet.net
 * updates: ap.stykers.moe
base                                                     | 3.6 kB     00:00     
extras                                                   | 3.4 kB     00:00     
teamviewer                                               | 2.5 kB     00:00     
updates                                                  | 3.4 kB     00:00     
Resolving Dependencies
--> Running transaction check
---> Package git.x86_64 0:1.8.3.1-20.el7 will be installed
--> Processing Dependency: perl-Git = 1.8.3.1-20.el7 for package: git-1.8.3.1-20.el7.x86_64
--> Processing Dependency: perl(Term::ReadKey) for package: git-1.8.3.1-20.el7.x86_64
--> Processing Dependency: perl(Git) for package: git-1.8.3.1-20.el7.x86_64
--> Processing Dependency: perl(Error) for package: git-1.8.3.1-20.el7.x86_64
--> Running transaction check
---> Package perl-Error.noarch 1:0.17020-2.el7 will be installed
---> Package perl-Git.noarch 0:1.8.3.1-20.el7 will be installed
---> Package perl-TermReadKey.x86_64 0:2.30-20.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                Arch         Version                Repository     Size
================================================================================
Installing:
 git                    x86_64       1.8.3.1-20.el7         updates       4.4 M
Installing for dependencies:
 perl-Error             noarch       1:0.17020-2.el7        base           32 k
 perl-Git               noarch       1.8.3.1-20.el7         updates        55 k
 perl-TermReadKey       x86_64       2.30-20.el7            base           31 k

Transaction Summary
================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 4.5 M
Installed size: 22 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): perl-Error-0.17020-2.el7.noarch.rpm                 |  32 kB   00:00     
(2/4): perl-TermReadKey-2.30-20.el7.x86_64.rpm             |  31 kB   00:00     
(3/4): perl-Git-1.8.3.1-20.el7.noarch.rpm                  |  55 kB   00:01     
(4/4): git-1.8.3.1-20.el7.x86_64.rpm                       | 4.4 MB   00:04     
--------------------------------------------------------------------------------
Total                                              1.0 MB/s | 4.5 MB  00:04     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:perl-Error-0.17020-2.el7.noarch                            1/4 
  Installing : perl-TermReadKey-2.30-20.el7.x86_64                          2/4 
  Installing : git-1.8.3.1-20.el7.x86_64                                    3/4 
  Installing : perl-Git-1.8.3.1-20.el7.noarch                               4/4 
  Verifying  : perl-Git-1.8.3.1-20.el7.noarch                               1/4 
  Verifying  : 1:perl-Error-0.17020-2.el7.noarch                            2/4 
  Verifying  : git-1.8.3.1-20.el7.x86_64                                    3/4 
  Verifying  : perl-TermReadKey-2.30-20.el7.x86_64                          4/4 

Installed:
  git.x86_64 0:1.8.3.1-20.el7                                                   

Dependency Installed:
  perl-Error.noarch 1:0.17020-2.el7         perl-Git.noarch 0:1.8.3.1-20.el7    
  perl-TermReadKey.x86_64 0:2.30-20.el7    

Complete!

以上说明安装成功

3、再使用 rpm -qa|grep git 来查看是否已经安装好了Git

rpm -qa|grep git 
[root@hp-hp summergao]# rpm -qa|grep git 
git-1.8.3.1-20.el7.x86_64
lm_sensors-libs-3.4.0-6.20160601gitf9185e5.el7.x86_64
hyperv-daemons-0-0.34.20180415git.el7.x86_64
hypervvssd-0-0.34.20180415git.el7.x86_64
libglvnd-egl-1.0.1-0.8.git5baa1e5.el7.x86_64
hypervkvpd-0-0.34.20180415git.el7.x86_64
libglvnd-glx-1.0.1-0.8.git5baa1e5.el7.x86_64
hyperv-daemons-license-0-0.34.20180415git.el7.noarch
python-dns-1.12.0-4.20150617git465785f.el7.noarch
libglvnd-gles-1.0.1-0.8.git5baa1e5.el7.x86_64
lldpad-1.0.1-3.git036e314.el7.x86_64
ipxe-roms-qemu-20170123-1.git4e85b27.el7_4.1.noarch
hypervfcopyd-0-0.34.20180415git.el7.x86_64
xdg-utils-1.1.0-0.17.20120809git.el7.noarch
net-tools-2.0-0.24.20131004git.el7.x86_64
linux-firmware-20180911-69.git85c5d90.el7.noarch
numad-0.5-18.20150602git.el7.x86_64
taglib-1.8-7.20130218git.el7.x86_64
lockdev-1.0.4-0.13.20111007git.el7.x86_64
libglvnd-1.0.1-0.8.git5baa1e5.el7.x86_64
crontabs-1.11-6.20121102git.el7.noarch
[root@hp-hp summergao]# 

4、创建Git仓库

mkdir six_git                             // 创建文件夹
useradd six                               //创建用户名并设置密码
passwd six                                //(系统会提示输入密码和再次密码)
groupadd git                              // 创建组
git init --bare                           //进入所创建的文件夹,初始化一个仓库
chown -R six:git /var/www/six_git/        // 赋权限

5、 禁止shell登陆

出于安全考虑,git用户不允许登录shell,这可以通过编辑/etc/passwd文件完成。
找到类似下面的一行:

six:x:502:502::/home/six:/bin/bash
改为
six:x:502:502::/home/six:/usr/local/git/bin/git-shell
或者
six:x:502:502::/home/six:/usr/bin/git-shell
six:x:502:502::/home/six:/bin/false

git用户可以正常通过ssh使用git,但无法登录shell,因为我们为git用户指定的git-shell每次一登录就自动退出。

参考:https://www.centos.bz/2018/03/centos7%E6%90%AD%E5%BB%BAgit%E5%8F%8A%E5%AE%89%E8%A3%85%E4%BD%BF%E7%94%A8/

转载于:https://my.oschina.net/zhenggao/blog/3044748

你可能感兴趣的:(Centos 7 搭建Git及安装使用)