Git SSH 配置

Step 1: 检查本地是否已经存在key文件

1
2
cd ~/.ssh
$ ls -al

如果文件列表里面有 id_rsa.pub或者 id_das.pub,你可以跳过Step2 直接到Step3.


Step 2: 生成一个新的SSH Key

1
2
3
4
5
6
7
8
9
10
$ ssh-keygen -t rsa -C "your_email@example.com"
# 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 (/c/Users/you/.ssh/id_rsa): [Press enter]
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
Your identification has been saved in /c/Users/you/.ssh/id_rsa.
# Your public key has been saved in /c/Users/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 your_email@example.com

Then add your new key to the ssh-agent

1
$ ssh-add ~/.ssh/id_rsa


Step 3 添加SSH key 到github

  1. In the user bar in the top-right corner of any page, click Account settings.
  2. Click SSH Keys in the left sidebar.
  3. Click Add SSH key.
  4. In the Title field, add a descriptive label for the new key. For example, if you’re using a personal Mac, you might call this key “Personal MacBook Air”.
  5. Paste your key into the “Key” field.
  6. Click Add key.
  7. Confirm the action by entering your GitHub password.

Step 4: 测试SSH

1
2
3
4
$ ssh -T git@github.com
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)?
Hi username! You've successfully authenticated, but GitHub does not provide shell access.

原文 GitHub Hepl SSH.