git服务器的搭建
Posted 赵杰迪
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了git服务器的搭建相关的知识,希望对你有一定的参考价值。
GitHub就是一个免费托管开源代码的远程仓库。但是对于某些视源代码如生命的商业公司来说,既不想公开源代码,又舍不得给GitHub交保护费,那就只能自己搭建一台Git服务器作为私有仓库使用。
1 安装git
[[email protected] ~]# yum install git -y
2 创建用户
[[email protected] ~]# useradd git
[[email protected] ~]# passwd git
Changing password for user git.
New password:
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully
3 创建证书登陆
[[email protected] ~]# su - git [[email protected] ~]$ ssh-keygen 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: 70:bf:a4:85:a7:b5:83:aa:41:ff:0f:14:59:9f:bd:04 [email protected] The key‘s randomart image is: +--[ RSA 2048]----+ | . E | | o . + | | . + o o | | o + . . | | . S * . | | . . . O o | | . . = + | | . o . . | | ... ... | +-----------------+
4 初始化git仓库
[[email protected] ~]$ su - root Password: [[email protected] ~]# cd /app/dirtest/ [[email protected] dirtest]# mkdir gitserver [[email protected] dirtest]# cd gitserver/ [[email protected] gitserver]# chown -R git:git /app/dirtest/gitserver/ [[email protected] gitserver]# git init --bare sample.git Initialized empty Git repository in /app/dirtest/gitserver/sample.git/
5 禁用shell登陆
[[email protected] gitserver]# ll /usr/bin/git* -rwxr-xr-x. 105 root root 1138048 Aug 17 08:00 /usr/bin/git -rwxr-xr-x. 1 root root 1138056 Aug 17 08:00 /usr/bin/git-receive-pack -rwxr-xr-x. 1 root root 457528 Aug 17 08:00 /usr/bin/git-shell -rwxr-xr-x. 1 root root 1138056 Aug 17 08:00 /usr/bin/git-upload-archive -rwxr-xr-x. 1 root root 467824 Aug 17 08:00 /usr/bin/git-upload-pack [[email protected] gitserver]# echo "/usr/bin/git-shell" >> /etc/shells [[email protected] gitserver]# chsh -s /usr/bin/git-shell git Changing shell for git. Shell changed.
6 导入证书
[[email protected] gitserver]# cat /root/.ssh/id_rsa.pub >> /home/git/.ssh/authorized.keys
7 克隆仓库
[[email protected] gitclient]# git clone [email protected]:/app/dirtest/gitserver/sample.git Initialized empty Git repository in /app/dirtest/gitclient/sample/.git/ The authenticity of host ‘centos6.magedu.com (172.18.1.159)‘ can‘t be established. RSA key fingerprint is e2:1d:9f:d2:47:c9:c3:79:68:b9:65:ee:13:36:75:51. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added ‘centos6.magedu.com,172.18.1.159‘ (RSA) to the list of known hosts.
以上是关于git服务器的搭建的主要内容,如果未能解决你的问题,请参考以下文章