Build git under CentOS and access via Windows client

Source: Internet
Author: User
Tags centos server

Pro-Test on the local virtual machine and remote server no problem, if you do not understand please leave a message.

Note: All of the following actions are operating under root authority.
1.Centos Server version
centos6.5

2. Install git first and install it online using Yum

1 yum install-y git

Installation Successful

3. Create a git user to run the GIT service

1 adduser git

4. Create a git repository directory and initialize it
A. Create a directory First:

1 mkdir-p/mydata/git/gitrepo.git

B. Initialize the GIT repository:

1 cd/mydata/git2 git init--bare gitrepo.git

5. Change the ownership and group of files

Chown Git:git Gitrepo.git

Cause: Because the GIT repository on the server is purely for sharing, it does not allow users to log on directly to the server to change workspaces, and the Git repositories on the server usually end in. git.

6. We can clone the remote repository on the client
Note: The Git tool needs to be installed on the Windows platform
Msysgit Official website: https://git-for-windows.github.io/
Cloud Disk Download: Https://yunpan.cn/ckGKthxzFJ4RD access password a01f

1 git clone [email protected]:/mydata/git/gitrepo.git

Here are two points to note: First, the first time you use Git's clone or push to connect to git, you get a warning:

This is because Git uses SSH connection, and SSH connection is the first time to verify the GitHub server key, you need to confirm that GitHub key fingerprint information is really from the GitHub server, enter Yes.
Git will output a warning telling you that you have added GitHub key to a trust list on this machine.

This warning will only appear once, and there will be no warning after the operation.
If you are really worried about someone impersonating a github server, enter Yes before you can control whether the fingerprint information of GitHub's RSA key is consistent with the SSH connection.
Second, you are prompted to enter a password to clone, of course, if you know the password, you can type a password to clone, but the more common way is to use the SSH public key to complete the verification.

7. Create SSH key
First in the User Home directory (window generally in the C-drive, user files), see if there is no. ssh directory, if there is, then look at this directory there are no Id_rsa and id_rsa.pub these two files, if already have, can jump directly to the next step. If not, open the shell (open git Bash under Windows) and create SSH Key:

If all goes well, you can find the. SSH directory in the user's home directory, there are Id_rsa and id_rsa.pub two files, these two are SSH key key pair, Id_rsa is the private key, can not be leaked out, Id_rsa.pub is the public key, can be assured to tell anyone.

1 " [email protected] "

8.Git Server Open RAS authentication

1 vim/etc/ssh/sshd_config

Modify:
1.RSAAuthentication Yes
2.PubkeyAuthentication Yes
3.AuthorizedKeysFile. Ssh/authorized_keys

Here we can see that the public key is stored in the. ssh/authorized_keys file. So we create the. SSH directory under/home/git, then create the Authorized_keys file and import the public key that you just generated. (in the case of Linux in a virtual machine, you can connect to the local virtual machine via SSH.) First use Ifconfig to look at the IP in the LAN, and then connect in the SSH tool. View virtual machine IP 192.168.130.134)

Then when cloning again, or after the push, there is no need to enter the password:

git clone [email protected]192.168. 130.134:/mydata/git/learngit.git

9. Disable GIT user shell login
For security reasons, the GIT user created in the second step is not allowed to log in to the shell, which can be done by editing the/etc/passwd file.

1 vim/etc/passwd

Find a line similar to the following:
git:x:1001:1001:,,,:/home/git:/bin/bash
Switch
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell

In this way, git users can use git normally via SSH, but cannot log in to the shell because the Git-shell we specify for git users automatically exits every time a login is logged in.

Build git under CentOS and access via Windows client

Related Article

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.