1. 程式人生 > >Linux 下搭建git 服務器

Linux 下搭建git 服務器

domain 目錄結構 倉庫 read -i shel for public git clone

環境: 服務器 centos7.3 +git1.8.3.1
客戶端 centos7.2 +git1.8.3.1
服務器配置;
1.安裝git yum install git -y
2.創建git用戶
[[email protected] ~]# id git
id: git: no such user
[[email protected] ~]# useradd git
[[email protected] ~]# id git
uid=1001(git) gid=1001(git) groups=1001(git)

為了安全起見,可以只允許git使用git命令

sed -i ‘/^git/s#/bin/bash#/usr/bin/git-shell#g‘ /etc/passwd
3.在服務端創建git倉庫
把/data/git/test.git設置為GIT倉庫,並修改屬主屬組為git
[[email protected] ~]# mkdir -p /data/git/test.git
[[email protected] ~]# git init --bare /data/git/test.git #--bare參數創建目錄結構
Initialized empty Git repository in /data/git/test.git/
[[email protected]

/* */ ~]# chown -R git.git /data/git/test.git
[[email protected] ~]# cd /data/git/test.git/
[[email protected] test.git]# ll
total 12
drwxr-xr-x. 2 git git 6 Jun 28 22:57 branches
-rw-r--r--. 1 root root 66 Jun 28 22:58 config
-rw-r--r--. 1 git git 73 Jun 28 22:57 description
-rw-r--r--. 1 git git 23 Jun 28 22:57 HEAD
drwxr-xr-x. 2 git git 242 Jun 28 22:57 hooks
drwxr-xr-x. 2 git git 21 Jun 28 22:57 info
drwxr-xr-x. 4 git git 30 Jun 28 22:57 objects
drwxr-xr-x. 4 git git 31 Jun 28 22:57 refs

客戶端配置:
1.安裝git yum install git -y
2.配置免密鑰登錄
[[email protected]
/* */ ~]#ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
ac:be:d1:12:37:89:1b:ca:52:8b:4c:b7:97:38:18:41 [email protected]
The key‘s randomart image is:
+--[ RSA 2048]----+
| E |
| . |
| . |
| . o . |
| o o + S |
| o B = O . |
| = B B . |
| . + o |
| o. |
+--------------------+
[[email protected] ~]# ssh-copy-id 192.168.138.133
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected] password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh ‘192.168.138.133‘"
and check to make sure that only the key(s) you wanted were added.
3.創建本地倉庫
[[email protected] ~]# mkdir /git
[[email protected] ~]# cd /git/
[[email protected] git]# ll
total 0
[[email protected] git]# git clone 192.168.138.133:/data/git/test.git/
Cloning into ‘test‘...
warning: You appear to have cloned an empty repository.
[[email protected] git]# ll
total 0
drwxr-xr-x. 3 root root 17 Jul 3 20:42 test

Linux 下搭建git 服務器