千家信息网

CentOS如何搭建Git服务器

发表于:2025-11-13 作者:千家信息网编辑
千家信息网最后更新 2025年11月13日,这篇文章主要讲解了"CentOS如何搭建Git服务器",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"CentOS如何搭建Git服务器"吧!一 确认服务器
千家信息网最后更新 2025年11月13日CentOS如何搭建Git服务器

这篇文章主要讲解了"CentOS如何搭建Git服务器",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"CentOS如何搭建Git服务器"吧!

一 确认服务器是否安装git

[root@iz25r8k6ifuz git]# rpm -qa gitgit-1.7.1-3.el6_4.1.x86_64

这里也已经安装过了,如果没有安装可以用yum install git 安装。

二 创建git用户

这里你可以选择新建一个用户来测试,也可以直接使用你的root进行以下操作。笔者也是看着资料一步一步来的,这里创建一个新用户teslachen进行操作。

[root@iz25r8k6ifuz ~]# useradd tesla[root@iz25r8k6ifuz ~]# passwd tesla

更改用户 tesla 的密码 。

新的 密码:

无效的密码: 它没有包含足够的不同字符

无效的密码: 过于简单

重新输入新的 密码:

passwd: 所有的身份验证令牌已经成功更新。

注1:创建用户权限不够请加上sudo;

注2:设置用户密码太过简单的话会有提示,但依旧可以设置成功。

三 生成ssh公钥

许多 git 服务器都使用 ssh 公钥进行认证。 为了向 git 服务器提供 ssh 公钥,如果某系统用户尚未拥有密钥,必须事先为其生成一份。

linux 可以在本机运行ssh-keygen -t rsa生成密钥,把.pub文件拷到服务器上。

[root@iz25r8k6ifuz ~]# su tesla[tesla@iz25r8k6ifuz root]$ cd ~[tesla@iz25r8k6ifuz ~]$ mkdir .ssh[tesla@iz25r8k6ifuz ~]$ ssh-keygen -t rsagenerating public/private rsa key pair.enter file in which to save the key (/home/tesla/.ssh/id_rsa):enter passphrase (empty for no passphrase):enter same passphrase again:your identification has been saved in /home/tesla/.ssh/id_rsa.your public key has been saved in /home/tesla/.ssh/id_rsa.pub.the key fingerprint is:13:bf:75:ba:67:7f:0e:a0:47:7a:fe:25:bc:81:85:c3 tesla@iz25r8k6ifuzthe key's randomart image is:+--[ rsa 2048]----+|     ||     ||  .  ||   o . . ||  s . e o ||   . o ||   + = = .||   + .o.||   o+oo+|+-----------------+[tesla@iz25r8k6ifuz ~]$ cd .ssh/[tesla@iz25r8k6ifuz .ssh]$ cat id_rsa.pub >> ~/.ssh/authorized_keysexit

四 添加tesla到sudoers文件

tesla用户现在对一些文件夹没有操作权限,修改/etc/sudoers文件来改变他的权限。最高管理员用户用下面命令打开。

[root@iz25r8k6ifuz ~]# visudo

然后我们在vim中找到下面这行

root all=(all) all

按i键开始插入,回车一下在下面一行加上

tesla all=(all) all

接着按下esc键,输入 :wq ,回车保存退出

五 创建git代码仓库

[root@iz25r8k6ifuz ~]# mkdir /teslarepo[root@iz25r8k6ifuz ~]# cd /teslarepo/[root@iz25r8k6ifuz teslarepo]# sudo mkdir teslaproject.git[root@iz25r8k6ifuz teslarepo]# chown tesla:tesla /teslarepo/[root@iz25r8k6ifuz teslarepo]# chown -r tesla:git /teslarepo/[root@iz25r8k6ifuz teslarepo]# cd teslaproject.git/[root@iz25r8k6ifuz teslaproject.git]# sudo git --bare initinitialized empty git repository in /teslarepo/teslaproject.git/

这样一个叫teslaproject得git仓库就创建好了

六 本地测试使用

你可以直接在服务器上进行本地测试,也可以直接用你的电脑来测试。下面我是使用自己的mbp来进行的测试。

localhost:~ okay$ cd desktop/git/localhost:git okay$ mkdir teslarepolocalhost:git okay$ cd teslarepo/localhost:teslarepo okay$ git initinitialized empty git repository in /users/okay/desktop/git/teslarepo/.git/localhost:teslarepo okay$ git remote add origin tesla@123.57.159.74:/teslarepo/teslaproject.git

上面的命令在本地创建了一个文件夹并添加了服务器上的远程仓库

localhost:teslarepo okay$ touch a.txtlocalhost:teslarepo okay$ git add a.txtlocalhost:teslarepo okay$ git commit -m "init commit"[master (root-commit) d14cd3b] init commit 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 a.txt

上面的命令在本地创建了一个a.txt并在本地提交了一次

localhost:teslarepo okay$ git push origin mastertesla@123.57.159.74's password:counting objects: 3, done.writing objects: 100% (3/3), 202 bytes | 0 bytes/s, done.total 3 (delta 0), reused 0 (delta 0)to tesla@123.57.159.74:/teslarepo/teslaproject.git * [new branch]  master -> master

上面的命令将本地代码push到远程服务器上去了,下面我们在本地clone一次看下是否正确

七 本地clone

localhost:git okay$ mkdir tttlocalhost:git okay$ cd tttlocalhost:ttt okay$ git clone tesla@123.57.159.74:/teslarepo/teslaproject.gitcloning into 'teslaproject'...tesla@123.57.159.74's password:remote: counting objects: 3, done.remote: total 3 (delta 0), reused 0 (delta 0)receiving objects: 100% (3/3), done.checking connectivity... done.

clone完成,让我们看一下文件夹目录

之前push到服务器上的a.txt文件已经被clone下来

------------分割线-------------

1. 查看系统用户组

-d:指定字段的分隔符,默认的字段分隔符为"tab";
-f:显示指定字段的内容;

cut -d: -f1 /etc/group

2. 查看系统用户

cut -d: -f1 /etc/passwd

3. clone仓库

git clone git@your_gitserver_ip:/home/gitrepo/sample.git

4. push已有仓库

// 以master分支示范git checkout mastergit remote rm origingit remote add origin git@your_gitserver_ip:/home/gitrepo/sample.gitgit push -u origin master

感谢各位的阅读,以上就是"CentOS如何搭建Git服务器"的内容了,经过本文的学习后,相信大家对CentOS如何搭建Git服务器这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!

服务器 服务 用户 文件 密码 仓库 测试 命令 公钥 内容 字段 文件夹 权限 系统 面的 学习 成功 代码 分隔符 密钥 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 创想视界互联网科技有限公司 益川软件开发怎么样 潼南区一站式网络技术是什么 怎么买我的世界服务器 vs2010内置sql数据库 软件开发寻项目 现代战舰服务器区名是什么 消费全返软件开发 吉林新一代软件开发价格服务标准 db2查看数据库表分区 淘宝商城软件开发店铺 网页如何登陆gdc服务器 微软软件开发集团有限公司 什么时候用数据库转换技术 纯软件开发模型 国脉科技互联网医疗 幻塔综合服务器哪个区人多 王者怎么回到之前的服务器 疫情期间网络安全培训 数据库修改视图中某学生的信息 城关区网络安全宣传周活动 软件开发实例经验总结 数据库的系统特点分别是 幼儿主题网络安全小卫士 湖南网络技术学院怎么样 戴尔服务器更换电源模块不匹配 广州小程序软件开发解决方案 湖南软件开发学校哪个比较好 测cf服务器延迟 软件开发适合哪些人
0