Adding an SSH Key[查 看 全 文]

Links to invite

  • GitHub Help
  • Refer to the connection


1. View the existing SSH key

$ ls -al ~/.ssh
Copy the code


Generate a new SSH key

2.1 Enter the GitHub Email Address as required

$ ssh-keygen -t rsa -b 4096 -C "[email protected]" 
Copy the code

2.2 File Generation Position

Enter file in which to save the key (/Users/ XXX /.ssh/id_rsa): [Press Enter]/* Press Enter to default file location */Copy the code

2.3 Setting the Push Password

Enter passphrase (empty for no passphrase): Enter same passphrase again: /* Set the password for the push fileCopy the code


3. Add the SSH key to the Ssh-agent

3.1 Starting the Ssh-Agent in the Background

$ eval "$(ssh-agent -s)"
> Agent pid 59566
Copy the code

3.2 to modify~/.ssh/configFile to automatically load the key into the SSH-Agent and store the password in the keychain

Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
Copy the code

3.3 Adding an SSH Private Key to the SSH-Agent and storing the password in the key chain

$ ssh-add -K ~/.ssh/id_rsa
Copy the code


Add the key to GitHub

  1. Open the file /.ssh/id_rsa.pub and copy the contents to the clipboard

  2. Click your profile picture in the upper right corner.

  3. Click on the Settings

  4. Click SSH and GPG keys

  5. Click New SSH Key

  6. Fill in the Title and paste the contents of the /.ssh/id_rsa.pub file into the Key

  7. Click Add SSH Key to finish

  8. If prompted, confirm your GitHub password


5. Test SSH connections

$ ssh -T [email protected]
Copy the code