One, build ideas (very important!!)
There are two main aspects, Git repository and project repository.
You need to have a Git repository (provider) on your server
2. Local repository, your server project repository, or other server repository (actual user), developed or online repository
Two, the construction process
My server is: CentOS6.* version (7.0 + changes do not know how to make it, you can step on the pit)
1. Install Git on the server
# yum install -y git
Copy the code
After executing the command, you can check out the version $git --versionCopy the code
[root@iZ2zeftluibm3hesz36v3tZ ~]# git --versionThe git version 1.7.1Copy the code
2. After the installation is complete, you need to create a user on the server to manage Git repository and set the password (I set the user with Git name).
Check to see if there is a Git user
[root@iZ2zeftluibm3hesz36v3tZ ~]# id git
Copy the code
Add the git user
[root@iZ2zeftluibm3hesz36v3tZ ~]# useradd git
Copy the code
Set a password for the Git user
passwd git
Copy the code
3. Core, now you need to select a directory on your server to put your version inventory in
OK, let’s create a directory for the repository
[root@iZ2zeftluibm3hesz36v3tZ home]# mkdir -p test/git
Copy the code
You can then create your new project address in this directory
[root@iZ2zeftluibm3hesz36v3tZ git]# mkdir -p aa.git
Copy the code
Take a look at it when you’re done
[root@iZ2zeftluibm3hesz36v3tZ git]# ll
total 12
drwxr-xr-x 2 root root 4096 Feb 2 15:04 aa.git
drwxrwxrwx 7 git git 4096 Jan 4 14:38 gittest.git
drwxrwxrwx 8 git git 4096 Jan 4 14:34 shop.git
Copy the code
Then you need to initialize the project.
[root@iZ2zeftluibm3hesz36v3tZ git]# git init --bare aa.git
Initialized empty Git repository in /home/test/git/aa.git/
Copy the code
As you can see above, aa.git belongs to the root user, now change it to git user (if you create another user, change it to another user).
[root@iZ2zeftluibm3hesz36v3tZ git]# chown -R git:git aa.git/
[root@iZ2zeftluibm3hesz36v3tZ git]# lltotal 12 drwxr-xr-x 7 git git 4096 Feb 2 15:06 aa.git drwxrwxrwx 7 git git 4096 Jan 4 14:38 gittest.git drwxrwxrwx 8 git git 4096 Jan 4 14:34 shop.gitCopy the code
After the git repository of the above server has been set up, we need to clone the local clone (development use) and the project storage directory (test library or project library) on the server.
Local repository, server (test) repository, and. SSH configuration process
1, Ok, now in your local, select a directory as the local development project repository (39.105.78.33 is your server extranet IP) you can also resolve into domain names.
Administrator@EZ-20170308TRRH MINGW64 /d/test
$ git clone[email protected]: / home /test/git/aa.git
Cloning into 'aa'. warning: You appear to have cloned an empty repository.Copy the code
If you find that you failed to clone, ok, that’s because you did not configure the SSH key.
In your local home directory, open Git Bash
$ ssh-keygen -t rsa -C "test.name@email"
Copy the code
Execute this command, and then you’ll be on your way to a stupid Yes
Then you will find it in the C:\Users\Administrator\.ssh directory
Id_rsa private key
Id_rsa.pub public key
After generation, on your server side
[root@iZ2zeftluibm3hesz36v3tZ .ssh]# cd /etc/ssh
[root@iZ2zeftluibm3hesz36v3tZ ssh]# vim sshd_config
Copy the code
Comment out the following three
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keysCopy the code
Save and restart the SSHD service:
[root@iZ2zeftluibm3hesz36v3tZ ssh]# /etc/rc.d/init.d/sshd restart
Copy the code
So let’s see
[root@iZ2zeftluibm3hesz36v3tZ .ssh]# cd ~
[root@iZ2zeftluibm3hesz36v3tZ ~]# ll -a
Copy the code
If you want to use one of the folders in your project as your project directory, you need to configure the public key on the server under the git user’s authority, which is authorized_keys in the.ssh of the git user we created
[root@iZ2zeftluibm3hesz36v3tZ ~]# ssh-keygen -t rsa -c 'your email'
[root@iZ2zeftluibm3hesz36v3tZ ~]# cd .ssh/
[root@iZ2zeftluibm3hesz36v3tZ .ssh]# ll -a
total 20
drwx------ 2 root root 4096 Jan 2 18:40 .
dr-xr-x---. 7 root root 4096 Jan 30 20:39 ..
-rw------- 1 root root 0 Dec 25 19:41 authorized_keys
-rw------- 1 root root 1675 Jan 2 18:08 id_rsa
-rw-r--r-- 1 root root 402 Jan 2 18:08 id_rsa.pub
-rw-r--r-- 1 root root 394 Jan 2 17:34 known_hosts
[root@iZ2zeftluibm3hesz36v3tZ .ssh]#
Copy the code
This is not where git users actually place their public keys. This is just one of your server’s public keys
Now let’s create the git user’s public key and Settings
[root@iZ2zeftluibm3hesz36v3tZ git]# pwd
/home/git
Copy the code
Create a SSH.
[root@iZ2zeftluibm3hesz36v3tZ git]# mkdir .ssh
[root@iZ2zeftluibm3hesz36v3tZ git]# ll -a
total 12
drwxr-xr-x 3 root root 4096 Jan 2 17:23 .
drwxr-xr-x. 4 root root 4096 Jan 2 17:22 ..
drwx------ 2 root root 4096 Jan 30 20:39 .ssh
[root@iZ2zeftluibm3hesz36v3tZ git]#
Copy the code
Now you must see the root permission group, now you need to change to git permission
[root@iZ2zeftluibm3hesz36v3tZ git]# chown -R git:git .ssh
[root@iZ2zeftluibm3hesz36v3tZ git]# ll -a
total 12
drwxr-xr-x 3 root root 4096 Jan 2 17:23 .
drwxr-xr-x. 4 root root 4096 Jan 2 17:22 ..
drwx------ 2 git git 4096 Jan 30 20:39 .ssh
Copy the code
Then we go back to our local Git Bash and import the local authorized_keys to the server
Administrator@EZ-20170308TRRH MINGW64 /d/test$SSH [email protected]'cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub
Copy the code
Now you can take a look
[root@iZ2zeftluibm3hesz36v3tZ git]# cd .ssh/
[root@iZ2zeftluibm3hesz36v3tZ .ssh]# ll -atotal 12 drwx------ 2 git git 4096 Jan 30 20:39 . drwxr-xr-x 3 root root 4096 Jan 2 17:23 .. -rw------- 1 git 1191 Jan 10 20:41 authorized_keys# chmod 700 .ssh
[root@iZ2zeftluibm3hesz36v3tZ git]# ll -a
total 12
drwxr-xr-x 3 root root 4096 Jan 2 17:23 .
drwxr-xr-x. 4 root root 4096 Jan 2 17:22 ..
drwx------ 2 git git 4096 Jan 30 20:39 .ssh
[root@iZ2zeftluibm3hesz36v3tZ .ssh]# chmod 600 authorized_keys
[root@iZ2zeftluibm3hesz36v3tZ .ssh]# ll -a
total 12
drwx------ 2 git git 4096 Jan 30 20:39 .
drwxr-xr-x 3 root root 4096 Jan 2 17:23 ..
-rw------- 1 git git 1191 Jan 10 20:41 authorized_keys
Copy the code
With this file, you can configure your key (C:\Users\Administrator\.ssh) or someone else’s key (C:\Users\Administrator\.ssh) in this location. Now you can clone the project.
In addition, the Git user you create can log in to the server using SSH if you want to disable it
[root@iZ2zeftluibm3hesz36v3tZ /]# vim /etc/passwd
Copy the code
Make the following changes
git:x:500:500::/home/git:/bin/bash
Copy the code
git:x:500:500::/home/git:/bin/bash-shellCopy the code
Basically here is the end, which has where to write bad, hope you leave a lot of messages, what questions you can leave a message, I see after basically will answer, write a little verbose, just hope to explain to the people who need to understand.