git connect with remote server

I am using the win10 system, connecting to github remotely, and the git server of the centos7 system of the virtual machine. The windows system is used as the client to connect to github and the git server in the virtual machine. Then I installed git and tortoisegit in win10. It is recommended to watch see the official tutorial

1. First install git in centos, the installation is very simple, the official website tutorial  , after installation, unlike other mysql, php and other software that need to be started, git does not need to be started, just use it directly, it transfers files through ssh , so you have to make sure your ssh is installed, if not, use yum install ssh

2. Create a new user on centos, or use an old user, but it is not easy to manage.

useradd git;//New user, the default user directory is /home/git

passwd git;//You need to set a password, you can't log in without setting it

3. In the git user directory

mkdir test;//Create a directory

git init --bare tmp.git;//Create a new warehouse, interested, you can see the difference between git init and git init --bare , so the warehouse is built

You also need to change the user and user group of this repository so that git users can access this path

chown -R git:git /home/git/tes/tmp.git;

4. On windows system

Where needed, directly git clone git@'server address':/home/git/test/tmp.git;//The server address is centos, ip address or domain name, if the domain name needs to be set up in dns first, or in the hosts file OK, add a "colon" after it, and then the warehouse path

Enter the git user password

5. Every time the operations of clone, push and pull are equal to the remote server, you need to enter the password, which is very troublesome. At this time, you can use asymmetric encryption to log in without password.

First generate the key  ssh-keygen -t rsa -C "email address"; the generated pair of keys are generally placed in C:\users\username\.ssh\, and then hit centos, in the git user directory Create a new directory .ssh, create a new file  authorized_keys, copy the contents of the public key generated on Windows to this file, and the public key suffix name is .pub, that’s it

6. How not to let the git user log in can set its shell, edit the /etc/passwd file, find the git user, and then change it to git-shell

7. How to install both git and tortoisegit, this needs to be set, find tortoisegit—”setting—” network, if you choose this ssh client, then the load Putty Key in your clone page should be set to Use the public key generated by putty, and then copy it to the public key on the remote server. Use the public key I drew the red line to copy to the authorized_keys file. If Load Putty Key is not checked, it is also necessary to copy the public key to the remote server. , because according to the ssh client, git will find the key generated by tortoisegit





Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325746418&siteId=291194637