您的位置:首页 > 编程语言

Github添加SSH Key

2015-12-01 23:26 357 查看
笔者操作系统是ubuntu

运行下面的命令创建SSH Key

ssh-keygen -t rsa -C "byhook@163.com"
邮箱为github登陆邮箱

然后根据提示输入github密码

Generating public/private rsa key pair.
Enter file in which to save the key (/home/byhook/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/byhook/.ssh/id_rsa.
Your public key has been saved in /home/byhook/.ssh/id_rsa.pub.
The key fingerprint is:
f5:9a:53:d3:97:d1:61:11:81:f6:9a:53:e1:c2:ab:62 byhook@163.com
The key's randomart image is:
+--[ RSA 2048]----+
|              .*+|
|             o..o|
|          . o o.o|
|         . . + +o|
|        S   + B..|
|           + * . |
|          + . .  |
|         E o     |
|        . .      |
+-----------------+


生成的id_rsa文件是私有密钥

id_rsa.pub是公开的密钥

查看公钥的内容

cat ~/.ssh/id_rsa.pub


输出结果

ssh-rsa 公钥内容 byhook@163.com


复制上述的内容



使用私钥和github进行认证

ssh -T git@github.com


结果显示

The authenticity of host 'github.com (192.30.252.131)' 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
Warning: Permanently added 'github.com,192.30.252.131' (RSA) to the list of known hosts.
Hi byhook! You've successfully authenticated, but GitHub does not provide shell access.


成功!!!

如果出现下图问题

Warning: Permanently added the RSA host key for IP address '192.30.252.131' to the list of known hosts.
Agent admitted failure to sign using the key.
Permission denied (publickey).
输入命令

ssh-add
输入密码

继续即可

使用SSH Key访问github



输入命令

git remote set-url origin git@github.com:byhook/IPCSample.git
OK

以后pull push都不用输入密码了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: