如何配置ssh秘钥

图文学习如何配置ssh秘钥

配置 git 的 ssh 秘钥流程

  1. 先检查系统内有没有 ssh 秘钥
  2. 配置 git
  3. 生成 ssh 秘钥
  4. 添加 ssh 秘钥
  5. 进行测试

具体步骤

第一步:找到 git 的安装目录,打开 git-bash.exe 文件

  

https://image.coderlab.cn/preview/1438620874205839362

  如图1所示

第二步:先检查系统内有没有 ssh 秘钥

1
cd  ~/.ssh

  

https://image.coderlab.cn/preview/1438620902005686273

  能打开就说明存在 ssh 秘钥 如果系统存在 ssh 秘钥,则请进行下一步

第三步:设置 git 的 userName 和 email(如果第一次使用 git)

  1 2 $git config –global user.name “你的用户名”$ git config –global user.email “你的邮箱” 如果已经进行过 git 基础设置,则请进行下一步

第四步:生成 ssh 秘钥

1
ssh-keygen -t rsa -C "你的邮箱"

  

https://image.coderlab.cn/preview/1438620920217354242

  如图3所示

第五步:添加 ssh 秘钥

  打开 github,选择需要添加 ssh 秘钥的项目仓库 接下来按图进行操作

  

https://image.coderlab.cn/preview/1438620943453798401

  如图4所示

第六步:进行测试

  在 git-bash.exe 输入以下指令进行测试

1
$ ssh -T git@github.com

  接下来你会看见

1
2
3
The authenticity of host 'github.com (192.30.255.113)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? Host key verification failed.

  选择 yes

1
Hi 你的用户名! You've successfully authenticated, but GitHub does not provide shell access.

  如果看见 Hi 后面是你的用户名就说明成功了