Github添加SSH Key

笔者操作系统是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都不用输入密码了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值