How to configure SSH keys on GitHub

Source: Internet
Author: User

I don't know why. The image and format will be lost when the csdn blog is saved. Please click here to share my youdao cloud notes.

Today, I specially translated the GitHub tutorial GitHub generating SSH keys into Chinese (not full-text translation). Because of my limited level, please note if you have any errors.
 The SSH key is used to confirm that you are the project administrator or owner, and you can use git without a password. Of course, you need to use SSH links when using GitHub. It doesn't matter if you use HTTPS.HTTPS can clone any project, but SSH can only clone your project. You must be the owner of this project. In addition, you do not need to enter the user name and password for SSH push, which makes it easy for users to use, provided that you have to add your SSH key on GitHub first.
 Because the csdn Code project also uses Git and is similar to GitHub, you can refer to this tutorial for csdn code.

Step 1: Check SSH keys

First, check whether your computer has SSH keys. Open your computer terminal and enter the following command:

ls -al ~/.ssh # Lists the files in your .ssh directory, if they exist

If you already have an SSH key, you will see the following default files.


  • Id_dsa.pub
  • Id_ecdsa.pub
  • Id_ed25519.pub
  • Id_rsa.pub
Then you can skip step 2 and go to step 3.

Step 2: Create a New SSH key

To generate a new SSH key, open the terminal and enter the following command, and enter your email. The default setting is the first choice. Therefore, when the system prompts "Enter the important file to be saved:", you only need to press enter to continue.


ssh-keygen -t rsa -C "[email protected]" # Creates a new ssh key, using the provided email as a label # Generating public/private rsa key pair. # Enter file in which to save the key (/home/you/.ssh/id_rsa):

Next, you need to enter the password. This password is used when the SSH link is used for push. You can set it if you do not want to press Enter.

If the following content is output, the key is successfully created.
# Your identification has been saved in /home/you/.ssh/id_rsa. # Your public key has been saved in /home/you/.ssh/id_rsa.pub. # The key fingerprint is: # 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]

Next, add the key you just created to the SSH-agent and execute the following two commands.

# start the ssh-agent in the background eval "$(ssh-agent -s)" # Agent pid 59566 ssh-add ~/.ssh/id_rsa
Step 3: add the SSH key to GitHub

Run the following command to copy the key to clipboard. The file name of the key isid_dsa.pub,id_ecdsa.pub Orid_ed25519.pubOr you can simply open these files and copy them using the gedit editor.

sudo apt-get install xclip # Downloads and installs xclip. If you don‘t have `apt-get`, you might need to use another installer (like `yum`) xclip -sel clip < ~/.ssh/id_rsa.pub # Copies the contents of the id_rsa.pub file to your clipboard

Then open your GitHub settings page, which contains an SSH keys

Click Add SSH keyPaste the copied file.

Step 4: Test

To ensure that everything works properly, you can test whether it can be properly linked to GitHub. During the test, you may be asked to enter the password,

Open your terminal and enter:

ssh -T [email protected] # Attempts to ssh to github

You may see the following error message:

... Agent admitted failure to sign using the key. debug1: No more authentication methods to try. Permission denied (publickey).

See the help document.

You may see the following warning:

# The authenticity of host ‘github.com (207.97.227.239)‘ can‘t be established. # RSA key fingerprint is 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)?

Don't worry. This is normal. Enter "yes" directly ".

# Hi username! You‘ve successfully authenticated, but GitHub does not # provide shell access.

If the user name is yours, you have successfully set the SSH key!

If you still cannot link to GitHub, you can refer to these articles.

If you switch from HTTPS to SSH, you need to update the URL of the remote repository. For more information, see Modify remote URLs.


How to configure SSH keys 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.