扩大
缩小

git服务器的搭建

GitHub就是一个免费托管开源代码的远程仓库。但是对于某些视源代码如生命的商业公司来说,既不想公开源代码,又舍不得给GitHub交保护费,那就只能自己搭建一台Git服务器作为私有仓库使用。

1 安装git

[root@centos6 ~]# yum install git -y

2 创建用户

[root@centos6 ~]# useradd git 
[root@centos6 ~]# 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 创建证书登陆

[root@centos6 ~]# su - git                    
[git@centos6 ~]$ 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 git@centos6.magedu.com
The key's randomart image is:
+--[ RSA 2048]----+
|          . E    |
|         o . +   |
|      . +   o o  |
|       o +   . . |
|    .   S *   .  |
|   . . . O o     |
|    . . = +      |
|     . o . .     |
|    ... ...      |
+-----------------+

4 初始化git仓库

[git@centos6 ~]$ su - root
Password: 
[root@centos6 ~]# cd /app/dirtest/
[root@centos6 dirtest]# mkdir gitserver
[root@centos6 dirtest]# cd gitserver/
[root@centos6 gitserver]# chown -R git:git /app/dirtest/gitserver/
[root@centos6 gitserver]# git init --bare sample.git
Initialized empty Git repository in /app/dirtest/gitserver/sample.git/

5 禁用shell登陆

[root@centos6 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
[root@centos6 gitserver]# echo "/usr/bin/git-shell" >> /etc/shells
[root@centos6 gitserver]# chsh -s /usr/bin/git-shell git
Changing shell for git.
Shell changed.

6 导入证书

[root@centos6 gitserver]# cat /root/.ssh/id_rsa.pub >> /home/git/.ssh/authorized.keys

7 克隆仓库

[root@centos6 gitclient]# git clone git@centos6.magedu.com:/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.

posted on 2017-11-11 14:49  LinuxPanda  阅读(455)  评论(0编辑  收藏  举报

导航