Git-设置SSH Key

        GitHub上连接已有仓库时的认证,是通过使用SSH的公开密钥认证方式进行的。我们首先来创建SSH key,并将其添加到GitHub上。

前提是要初始化设置姓名和邮箱地址

$ git config --global user.name "GraceSi"
$ git config --global user.email "your_email@163.com"


1、创建SSH Key

$ ssh-keygen -t rsa -C "your_email@163.com"

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/zhangsisi/.ssh/id_rsa): 按回车键
/c/Users/zhangsisi/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): 输入密码
Enter same passphrase again:再次输入密码 

输入密码后结果:

Your identification has been saved in /c/Users/zhangsisi/.ssh/id_rsa.
Your public key has been saved in /c/Users/zhangsisi/.ssh/id_rsa.pub.
The key fingerprint is:
fingerprint值 your_email@163.com
The key's randomart image is:
+---[RSA 2048]----+
|       ....o   +.|
|    . .   . + = o|
|     o o   o = + |
|    o =    .+ * +|
|   o B .S .+.+ =.|
|    o = ....*o+  |
|     o o o.. +oE |
|      * .     .+ |
|    .+        ..o|
+----[SHA256]-----+
id_rsa 文件时私有密钥   id_rsa.pub是公有密钥

2、获取公有密钥

$ cat ~/.ssh/id_rsa.pub
ssh-rsa 公开密钥内容 zhangsisi3034@163.com

3、GitHub添加公开密钥

点击GitHub有上角账户设置按钮(Setting),选择SSH and GPG keys,点击add ssh Key,出现如下内容。


4、测试认证成功

$ ssh -T git@github.com
The authenticity of host 'github.com (52.74.223.119)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known   hosts.
Enter passphrase for key '/c/Users/zhangsisi/.ssh/id_rsa':

出现下面结果证明成功

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


连接成功后,接下来每次连接github通过密钥进行认证,不需要再输入用户名和密码,简单方便。


  • 4
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值