git服务搭建在linux
要在Linux上搭建Git服务器,可以按照以下步骤进行操作:
安装Git软件包:使用命令`yum –y install git`来安装Git。
复制
创建新的空白仓库:通过运行`mkdir myrepo.git`命令来创建一个名为myrepo.git的目录,该目录将成为我们的Git仓库。
复制
初始化Git仓库:进入到myrepo.git目录中,并运行`git init --bare`命令来初始化一个空白的Git仓库。这样就完成了Git服务器的基本设置。
复制
配置SSH密钥认证(可选):如果希望只能通过SSH连接到Git服务器,可以生成公钥/私钥对,然后将公钥添加到authorized\_keys文件中。这样客户端才能与服务器进行身份验证。
复制
克隆现有仓库或者从头开始创建新项目:可以使用`git clone <repository>`命令来克隆已存在的Git仓库,也可以直接在myrepo.git目录中创建新的项目。
复制
其他高级功能:还可以配置Git Hooks、限制访问权限等更多高级功能,具体取决于自己的需求和喜好。
复制
注意事项:
-
Git服务器必须位于网络可达的地址,确保可以通过SSH或HTTPS协议访问。
-
确保正确设置了合适的文件权限,以及SELinux或AppArmor等安全机制的配置。
-
定期备份数据以防止数据丢失。
具体操作:
1、安装Git
yum install git Installed: git.x86_64 0:1.8.3.1-25.el7_9 Dependency Installed: perl-Error.noarch 1:0.17020-2.el7 perl-Git.noarch 0:1.8.3.1-25.el7_9 perl- Complete!
复制
1、安装Git
复制
2、创建Git用户和用户组
[root@VM-20-8-centos yum.repos.d]# groupadd git [root@VM-20-8-centos yum.repos.d]# useradd git -g git [root@VM-20-8-centos yum.repos.d]# passwd
复制
3、服务器端配置公钥
[root@VM-20-8-centos yum.repos.d]# su - git Last failed login: Fri Mar 29 03:02:32 CST 2024 from 43.155.153.75 on ssh:notty There were 60 failed login attempts since the last successful login. [git@VM-20-8-centos ~]$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/git/.ssh/id_rsa): Created directory '/home/git/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/git/.ssh/id_rsa. Your public key has been saved in /home/git/.ssh/id_rsa.pub. The key fingerprint is: SHA256:8aZi/d0FhLLzDPb12G/AnimIZCoMdQzjGne6Ci16Kmw git@VM-20-8-centos The key's randomart image is: +---[RSA 2048]----+ | | | o . | | . + . . . . | | . + + o o . | | = + S B .o | | .o . .o+ * .o= | |+ .o .o+o. .+..++| |oE. +.........+.o| |=o.. . . .....| +----[SHA256]-----+ [git@VM-20-8-centos ~]$ ls .ssh/ id_rsa id_rsa.pub [git@VM-20-8-centos ~]$ touch .ssh/authorized_keys
复制
4、初始化Git仓库
[git@VM-20-8-centos ~]$ git init --bare vc/qlc.git Initialized empty Git repository in /home/git/vc/aaa.git/
复制
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。