I. Preface
I have been using HTTPS to push the repository. The disadvantage is that I need to enter the account and password each time. If you use SSH, you do not need to enter the password.
Ii. Use
Single SSH
Using GitHub as the remote repository server only requires an SSH.
Generate SSH:
ssh-keygen -t rsa -C "[email protected]" -f ~/.ssh/github_id_rsa
By using the preceding command~ /. SSH (Windows in C:/users/admininstrator/. Ssh /)
Generate two files: github_id_rsa and github_id_rsa.pub. Save the private key and Public Key respectively.
View the public key:
cat ~/.ssh/github_id_rsa.pub
Run the preceding command to view the content of the github_id_rsa.pub file and output the public key,Copy the Public Key
Open GitHub and add the SSH public key:
Paste the copied Public Key in the key and enter the title at will.
Check whether the link is successful:
ssh -T [email protected]
Returns a statement containing successfully words, indicating that the link is successful.
Use SSH push/pull Repository:
Enter a repository and clone the repository SSH
Then, use the SSH
Git remote add GitHub 'ssh just copied'
In this way, you can use SSH for Push/pull.
Multiple SSH
When multiple git remote servers are used, such as code cloud and GitHub. In this case, you need to manage multiple SSH instances.
Generate public key
ssh-keygen -t rsa -C "[email protected]" -f ~/.ssh/gitee_id_rsassh-keygen -t rsa -C "[email protected]" -f ~/.ssh/github_id_rsa
The key here is to save the public key in different files, that is, to distinguish them.
View Public Key
cat ~/.ssh/github_id_rsa.pubcat ~/.ssh/gitee_id_rsa.pub
Add the public key to the remote server (Code cloud, GitHub) (omitted)
Configure config
In ~ /. SSH (Windows creates a config file in the C:/users/admininstrator/. Ssh/directory)(Excluding the extension)
. Add the following content to the file:
# giteeHost gitee.comHostName gitee.comPreferredAuthentications publickeyIdentityFile ~/.ssh/gitee_id_rsa# githubHost github.comHostName github.comPreferredAuthentications publickeyIdentityFile ~/.ssh/github_id_rsa
Check whether the connection is successful
$ ssh -T [email protected]$ ssh -T [email protected]
At the same time, the know_hosts file is generated in the. Ssh directory to distinguish different SSH
Use SSH to push and pull (omitted)
Tip: the configuration steps for a single SSH server and multiple SSH servers are not much different. When there are multiple SSH servers, you need to add a config file to differentiate SSH servers.
Use git SSH