1. 背景介绍

使用本地代码上传到 github 库的时候出现 Permission denied 错误

$ git push -u origin main
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

2. 错误原因

由于重装系统,之前的配置信息都不存在了,所以 SSL 的认证信息需要重新建立。

3. 解决方案

  • 在系统执行下面命令
    $ ssh-keygen -t rsa -b 4096 -C "Your Email Address"
  • 使用 cat 命令输出 id_rsa.pub 文件内的内容
    $ cat ~/.ssh/id_rsa.pub
  • 拷贝 cat 输出的内容到 github,github 的拷贝位置为 github.com/settings/keys。如果之前已经创建了 SSH key,只需要添加一个新的就可以了