Configure SSH Public Key logon on GitHub

Source: Internet
Author: User

For git installation, see the https://www.cnblogs.com/liliyang/p/9829931.html

Configure git to use the SSH key

Git supports both HTTPS and git transmission protocols. There are two optional protocols when you share a link with GitHub:

 

 

If git uses the HTTPS protocol, Every time pull and push prompts you to enter the password, use the GIT protocol, and then use the SSH key pair for authentication, you can achieve password-free authentication.

  Three steps are required to configure git password-free through the SSH protocol: 1. Generate a key pair 2. Configure the public key on the remote repository (GitHub is used here) 3. Change the GIT remote URL to the GIT protocol.(After the above two steps are set for the first time, you do not need to set them again for later use, This step depends on the remote URL of future projects. If the protocol for other projects in the future is https, this step is required.) 1. Generate a key pair
[[email protected] ~]# ssh-keygen  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:SHA256:fO7pVFqZ464nC8H6B3pTE8cwPx2mTM0G8KJt7Or2L8o [email protected]-node1The key‘s randomart image is:+---[RSA 2048]----+|          ...+   ||          o.. *  ||          .B.= . ||       o +..Bo.  ||        S =o*.   ||       ..*o= .   ||      ...o=..    ||      .o+=+o.    ||       +E*BBo    |+----[SHA256]-----+[[email protected]-node1 ~]# ll .ssh/total 8-rw------- 1 root root 1679 Oct 23 11:32 id_rsa-rw-r--r-- 1 root root  397 Oct 23 11:32 id_rsa.pub

[[Email protected] ~] # Cat. Ssh/id_rsa.pub
Ssh-RSA encrypt/2hdtjmzkhnd2kceupsibuemnh0j/upa0de/encrypt + encrypt/rsqn8wznqqozi8jqu + encrypt/decrypt + encrypt + yagdqtwlf7 [email protected]

Add the Public Key copy to the GitHub Public Key configuration.

 

2. Add the public key to your remote repository (GitHub)

Enter title casually

Copy the public key to the preceding key and click Add SSH key.

 

Test on the local host:

[[email protected]-node1 ~]# ssh -T [email protected]The authenticity of host ‘github.com (192.30.253.113)‘ can‘t be established.RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.RSA key fingerprint is MD5:16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added ‘github.com,192.30.253.113‘ (RSA) to the list of known hosts.Hi useyunwei! You‘ve successfully authenticated, but GitHub does not provide shell access.

 

 

3. Modify the GIT remote URL

Run the GIT remote-V command (which must be executed in the clone project directory in advance) to view your current remote URL.

The following code is executed in the directory of the libgit2 project.

[[Email protected] Game-of-Life] # git remote-V
Origin https://github.com/useyunwei/game-of-life.git (FETCH)
Origin https://github.com/useyunwei/game-of-life.git (push)

If the above result is returned, it indicates that the project is accessed using the HTTPS protocol (if the address starts with git, it indicates the GIT protocol)

You can log on to your GitHub, and you can see the URL of your SSH protocol above, similar:

 

Copy the above SSH link and then use the command git remote set-URL to adjust the URL.

[[Email protected] Game-of-Life] # git remote set-URL origin [email protected] B .com: useyunwei/game-of-life.git
[[Email protected] Game-of-Life] # git remote-V
Origin [email protected]: useyunwei/game-of-life.git (FETCH)
Origin [email protected]: useyunwei/game-of-life.git (push)

Run git remote-V again to check whether the URL has been changed to an SSH address.

Then you can use git fetch, git pull, and git push happily without entering the password.

 

Configure SSH Public Key logon on GitHub

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.