Github 配置SSH Key

一、SSH连接原理

在我们提交代码的时候, github需要用我们账号对应的公钥去解密我们提交的代码,如果能正确的解密说明当前提交代码的用户合法的。

所以在提交代码事先我们的电脑中需要持有一个私钥我们的github账户中也有持有一个公钥。

GitHub配置SSH Key的目的是为了帮助我们在通过git提交代码是,不需要繁琐的验证过程,简化操作流程。

二、设置git的username和email

初次安装 git 需要配置用户名和邮箱,否则git会提示:please tell me who you are.

你需要运行命令来配置你的用户名和邮箱:

git config --global user.name "username"
git config --global user.email  "email"

三、配置 SSH Key 免密登录步骤

1、检查是否存在SSH Key

看是否存在 id_rsa 和 id_rsa.pub文件,如果存在,说明已经有SSH Key

cd ~/.ssh
ls

2、生成SSH Key

运行以下命令,然后一直按回车确认

ssh-keygen -t rsa -C "email"

3、获取SSH Key

cat id_rsa.pub

4、在 github 中新增SSH Key

1.登录 GitHub
2.点击用户头像
3.Settings
4.SSHandGPG keys
5.New SHH Key
6.输入标题及公钥信息(上面复制 id_rsa.pub 文件内容)

参考:

https://blog.csdn.net/x550392236/article/details/123069751
https://www.jb51.net/article/241929.htm

本文链接: https://jianz.xyz/index.php/archives/98/

1 + 2 =
快来做第一个评论的人吧~