SSH配置
Checking for existing SSH keys
1、Open Terminal.
2、Enter ls -al ~/.ssh
to see if existing SSH keys are present:
ls -al ~/.ssh # Lists the files in your .ssh directory, if they exist
cat ~/.ssh/id_rsa.pub
# a long string starting withssh-rsa
Check the directory listing to see if you already have a public SSH key, By default, the filenames of the public keys are one of the following:
id_dsa.pub
id_ecdsa.pub
id_ed25519.pub
id_rsa.pub
If you see an existing public and private key pair listed (for example id_rsa.pub and id_rsa) that you would like to use to connect to GitHub
Generating a new SSH key
1、Open Terminal.
2、Paste the text below, substituting in your GitHub email address.
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
This creates a new ssh key, using the provided email as a label. Generating public/private rsa key pair.
When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location. just press enter to use the default
Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
Adding a new SSH key to your GitHub account
To copy your public key to the clipboard, use the code below. Depending on your OS you'll need to use a different command:
$ pbcopy < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
Click New SSH key or Add SSH key.then Click Add SSH key.
Testing your SSH connection
1、Open Terminal.
2、Enter the following:
ssh -T git@github.com #Attempts to ssh to GitHub
You may see one of these warnings:
The authenticity of host 'github.com (192.30.252.1)' 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)? The authenticity of host 'github.com (192.30.252.1)' can't be established. RSA key fingerprint is nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you want to continue connecting (yes/no)?
Note: The example above lists the GitHub IP address as 192.30.252.1. When pinging GitHub, you may see a range of IP addresses.
-
Verify that the fingerprint in the message you see matches the following message, then type
yes
:Hi username! You've successfully authenticated, but GitHub does not provide shell access.
-
If you're switching from HTTPS to SSH, you'll need to update your remote repository URLs.
官方文档
https://help.github.com/articles/generating-an-ssh-key/