github免输入密码

date: 2013.05.23

目录:

1 生成ssh key

输入命令:

ssh-keygen

一路回车, 会显示类似如下信息:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/test/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/test/.ssh/id_rsa.
Your public key has been saved in /home/test/.ssh/id_rsa.pub.
The key fingerprint is:
11:22:33:44:55:66:77:88:99:00:11:22:33:44:55:66 test@debian6
The key's randomart image is:
+--[ RSA 2048]----+
|+O=.. .          |
|o.+. o           |
|.F,   .          |
|*=x    .         |
|1+f,    S        |
| fdfdsa .        |
|o                |
| .               |
|                 |
+-----------------+

生成的默认路径在~/.ssh下, 其中id_rsa.pub是公钥, 上传到github即可.

2 将ssh key上传github

  1. 登录github

  2. 点击右上角的图标: "Account settings", 进入设置界面.

  3. 点击左边的"SSH Keys", 然后点击"Add key".

  4. 将刚刚生成的~/.ssh/id_rsa.pub中的全部字符拷贝到网页的弹出框中, 然后点击添加.

3 测试

测试之前, 请查看本地的github克隆中的.git/config文件中的字段

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@github.com:mikewootc/mikewootc.github.io.git

确认该字段中的url是git@打头, 而非https打头. 否则即使测试成功, 再push的仍然需要密码, 因为用的不是ssh方式认证. 如果不是的话, 将这行改过来即可.

然后本机命令行键入:

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)?

键入yes, 回车. 如果成功, 则会显示:

Hi mikewootc! You've successfully authenticated, but GitHub does not provide shell access.