Connect to GitHub with SSH

1. About SSH:

Using the SSH protocol, you can connect and authenticate to remote servers and services. With SSH Keys, connecting to GitHub doesn't have to be accessed every time

Both provide username and password.

 

2. Check Existing SSH Keys

Before you generate an SSH Key, you can check if you already have some SSH Keys.

(1)Open Terminal

(2) Enter  ls -al ~/.ssh whether there are some existing SSH Keys

(3)Check the directory listing to see if you already have a public SSH key.

By default, the filename of public keys is one of the following:

  • id_dsa.pub
  • id_ecdsa.pub
  • id_ed25519.pub
  • id_rsa.pub

  • If you don't have an existing public and private key pair, or don't wish to use any that are available to connect to GitHub, thengenerate a new SSH key. 

  • If you see an existing public and private key pair listed (for exampleid_rsa.pubandid_rsa) that you would like to use to connect to GitHub, you canadd your SSH key to the ssh-agent.    

3. Generate a new SSH Key and add it to ssh-agent

If you don't want to enter the password every time you use the SSH Key, you can add the key to the SSH agent and it will manage your

SSH key and remember the password.

3.1. Generate an SSH Key

(1) Open the terminal

(2) Execute ssh-keygen -t rsa -b 4096 -C [email protected]

(3) You will be prompted: "Enter a file in which to save the key," just press Enter.

 

3.2. Add the generated key to the ssh agent

(1) Start ssh-agent in the background : eval "$(ssh-agent -s)"

(2) Add your SSH private key to ssh-agent: ssh-add ~/.ssh/id_rsa

 

 

4. Add the Key to the Github account:

Just follow this article to do it:

https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/

5. Test the connection:

https://help.github.com/articles/testing-your-ssh-connection/#platform-linux

 

Here is the output of my successful connection:

[fanjg@localhost ~]$ ssh -T [email protected]
Hi gitFanjg! You've successfully authenticated, but GitHub does not provide shell access.

Guess you like

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