Git 教程之服务器搭建详解
作者:菜鸟教程 时间:2022-07-28 06:44:20
Git 服务器搭建
上一章节中我们远程仓库使用了 Github,Github 公开的项目是免费的,但是如果你不想让其他人看到你的项目就需要收费。
这时我们就需要自己搭建一台Git服务器作为私有仓库使用。
接下来我们将以 Centos 为例搭建 Git 服务器。
1、安装Git
$ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
$ yum install git
接下来我们 创建一个git用户组和用户,用来运行git服务:
$ groupadd git
$ adduser git -g git
2、创建证书登录
收集所有需要登录的用户的公钥,公钥位于id_rsa.pub文件中,把我们的公钥导入到/home/git/.ssh/authorized_keys文件里,一行一个。
如果没有该文件创建它:
$ cd /home/git/
$ mkdir .ssh
$ chmod 700 .ssh
$ touch .ssh/authorized_keys
$ chmod 600 .ssh/authorized_keys
3、初始化Git仓库
首先我们选定一个目录作为Git仓库,假定是/home/gitrepo/w3cschoolcc.git,在/home/gitrepo目录下输入命令:
$ cd /home
$ mkdir gitrepo
$ chown git:git gitrepo/
$ cd gitrepo
$ git init --bare w3cschoolcc.git
Initialized empty Git repository in /home/gitrepo/w3cschoolcc.git/
以上命令Git创建一个空仓库,服务器上的Git仓库通常都以.git结尾。然后,把仓库所属用户改为git:
$ chown -R git:git w3cschoolcc.git
4、克隆仓库
$ git clone git@192.168.45.4:/home/gitrepo/w3cschoolcc.git
Cloning into 'w3cschoolcc'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
192.168.45.4 为 Git 所在服务器 ip ,你需要将其修改为你自己的 Git 服务 ip。
这样我们的 Git 服务器安装就完成了,接下来我们可以禁用 git 用户通过shell登录,可以通过编辑/etc/passwd文件完成。找到类似下面的一行:
git:x:503:503::/home/git:/bin/bash
改为:
git:x:503:503::/home/git:/sbin/nologin
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SQL Server中通过reverse取某个最后一次出现的符号后面的内容(字符串反转)
Python数据结构与算法之图的基本实现及迭代器实例详解
![](https://img.aspxhome.com/file/2023/7/112617_0s.png)
pytorch中的广播语义
Python中Tkinter组件Button的具体使用
![](https://img.aspxhome.com/file/2023/1/131491_0s.png)
Python reduce函数作用及实例解析
![](https://img.aspxhome.com/file/2023/4/107494_0s.png)
javascript彩虹圈效果
asp,php 和 jsp 比较 之我见
![](https://img.aspxhome.com/file/UploadPic/20078/10/2007810135257787s.gif)
C#访问SQL Server数据库的实现方法
python 基于空间相似度的K-means轨迹聚类的实现
![](https://img.aspxhome.com/file/2023/4/90294_0s.png)
Python编程语言的35个与众不同之处(语言特征和使用技巧)
详解python中的IO操作方法
![](https://img.aspxhome.com/file/2023/9/123669_0s.png)
Bootstrap源码解读按钮(5)
用js实现键盘方向键翻页功能的代码
Python for循环搭配else常见问题解决
Windows下ORACLE 10g完全卸载的方法分析
SQL Server 在Management Studio中使用Web浏览器
![](https://img.aspxhome.com/file/2023/2/108542_0s.jpg)
Python回调函数用法实例详解
Python通过Pygame绘制移动的矩形实例代码
![](https://img.aspxhome.com/file/2023/7/105627_0s.gif)
Python supervisor强大的进程管理工具的使用
![](https://img.aspxhome.com/file/2023/0/75150_0s.png)