- [步骤](https://blog.csdn.net/u013778905/article/details/83501204#_10) - [一、设置git的user name和email](https://blog.csdn.net/u013778905/article/details/83501204#gituser_nameemail_11) - [二、检查是否存在SSH Key](https://blog.csdn.net/u013778905/article/details/83501204#SSH_Key_21) - [三、获取SSH Key](https://blog.csdn.net/u013778905/article/details/83501204#SSH_Key_46) - [四、GitHub添加SSH Key](https://blog.csdn.net/u013778905/article/details/83501204#GitHubSSH_Key_55) - [五、验证和修改](https://blog.csdn.net/u013778905/article/details/83501204#_65) ==https://github.com/xiangshuo1992/preload.git========git@github.com:xiangshuo1992/preload.git====== ==这两个地址展示的是同一个项目,但是这两个地址之间有什么联系呢?== ==前者是https url 直接有效网址打开,但是用户每次通过git提交的时候都要输入用户名和密码,有没有简单的一点的办法,一次配置,永久使用呢?当然,所以有了第二种地址,也就是SSH URL,那如何配置就是本文要分享的内容。== **GitHub配置SSH Key的目的是为了帮助我们在通过git提交代码是,不需要繁琐的验证过程,简化操作流程。** **步骤** **一、设置git的user name和email** ==如果你是第一次使用,或者还没有配置过的话需要操作一下命令,自行替换相应字段。== ==git config --global user.name "====zhensolid===="========git config --global user.email "====zhensolid@vip.qq.com===="== ==说明:git config --list 查看当前Git环境所有配置,还可以配置一些命令别名之类的。== **二、检查是否存在SSH Key** ==cd ~/.ssh========ls========或者========ll========//看是否存在 id_rsa 和 id_rsa.pub文件,如果存在,说明已经有SSH Key====== ==如下图== ![Exported image](IMG-20260516155659247.png) ==如果没有SSH Key,则需要先生成一下== ==ssh-keygen -t rsa -C "====zhensolid@vip.qq.com===="== ==执行之后继续执行以下命令来获取SSH Key== ==cd ~/.ssh========ls========或者========ll========//看是否存在 id_rsa 和 id_rsa.pub文件,如果存在,说明已经有SSH Key====== **三、获取SSH Key** ==cat id_rsa.pub========//拷贝秘钥 ssh-rsa开头====== ==如下图== ![Exported image](IMG-20260516155659345.png) **四、GitHub添加SSH Key** ==GitHub点击用户头像,选择setting== ![Exported image](IMG-20260516155659442.png) ==新建一个SSH Key== ![Exported image](IMG-20260516155659615.png) ==取个名字,把之前拷贝的秘钥复制进去,添加就好啦。== **五、验证和修改** ==测试是否成功配置SSH Key== ==d========//运行结果出现类似如下========Hi xiangshuo1992! You've successfully authenticated, but GitHub does not provide shell access.== ==之前已经是https的链接,现在想要用SSH提交怎么办?== ==直接修改项目目录下== ==.git====文件夹下的====config====文件,将地址修改一下就好了。== ==git地址获取可以看如下图切换。== ![Exported image](IMG-20260516155659688.png) ==END==