Build a git server under Linux

Source: Internet
Author: User
Tags create directory git clone git commands

Environment: Server centos7.3 +git1.8.3.1
Client centos7.2 +git1.8.3.1
Server configuration;
1. Installing git yum install git-y
2. Create a git user
[[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)

For security reasons, you can only allow git to use git commands

Sed-i '/^git/s#/bin/bash#/usr/bin/git-shell#g '/etc/passwd
3. Create a git repository on the server
Set the/data/git/test.git as a git repository and modify the owner group to git
[Email protected] ~]# mkdir-p/data/git/test.git
[[email protected] ~]# git init--bare/data/git/test.git #--bare parameter Create directory structure
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 June 22:57 branches
-rw-r--r--. 1 root root (June) 22:58 Config
-rw-r--r--. 1 git git June 22:57 description
-rw-r--r--. 1 git git 22:57 HEAD
Drwxr-xr-x. 2 git git 242 June 22:57 Hooks
Drwxr-xr-x. 2 git git June 22:57 info
Drwxr-xr-x. 4 git git 22:57 objects
Drwxr-xr-x. 4 git git to June 22:57 refs

Client Configuration:
1. Installing git yum install git-y
2. Configure a key-free login
[[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 is already installed
/usr/bin/ssh-copy-id:info:1 key (s) remain to being installed--if you are prompted now it's to install the new keys
[email protected] ' s password:

Number of key (s) added:1

Now try logging to the machine, with: "SSH ' 192.168.138.133 '"
And check to make sure that is only the key (s) wanted were added.
3. Create a local warehouse
[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 has cloned an empty repository.
[email protected] git]# LL
Total 0
Drwxr-xr-x. 3 root root 3 20:42 test

Build a git server under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.