配置 Github 密匙

最近总是搬家,电脑也跟着总是还,然后总是要重新配置 Github 密匙,所以特此记录一下,方便查阅。

设置 Git 的默认 用户名 和 邮箱

这个操作一般只有在第一次才做。

1
2
git config --global user.name "feke"
git config --global user.email "feke9432@gmail.com"

生成 密匙

注意这个操作不能使用 VSCode 的命令行,建议就使用 git bush

如果不需要密码,按 3 次回车就好。

1
ssh-keygen -t rsa -C "humingx@yeah.net"

成功后,生成两个文件:id_rsaid_rsa.pub,在C:\Users\你的用户名\.ssh,下,这是个隐藏文件夹。

给 Github 上传密匙

其中 .pub 文件就是公用密匙,右键记事本打开复制内容后;

登陆 Github 网页,点击右上角头像旁边的箭头,选择 setting ,在左侧选项卡中选中 SSH 字样的选项,添加密匙就好。

测试密匙上传成功与否

1
ssh -T git@github.com

然后选择 yes,如果最后在 HI 后面出现你的用户名,那就是密匙上传成功了。

1
2
3
4
5
The authenticity of host 'github.com (13.250.177.223)' 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,13.250.177.223' (RSA) to the list of known hosts.
Hi feke9432! You've successfully authenticated, but GitHub does not provide shell access.