如何使用 SSH 将我的存储库推送到 GitHub?

KAE*_*EDE 5 php git ssh github htdocs

如何使用 SSH 将我的存储库推送到 Github?

为什么

我想在 PHP 学习期间在 GitHub 上托管我的存储库。

我做了什么

我将远程 url 设置为kaede0902/phpto htdocs/workspace,并尝试拉取。我用的是须藤。

错误信息

kaede@kaede-ThinkPad-T450:/opt/lampp/htdocs/workspace$ sudo git pull origin master
Warning: Permanently added the RSA host key for IP address '52.69.186.44' to the list of known hosts.
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.
Run Code Online (Sandbox Code Playgroud)

我的 ssh 网址是git@github.com:kaede0902/php.git.

我正在使用 ssh 连接其他存储库。

问题是什么?

Cod*_*ard 11

您必须将 ssh 密钥添加到两台机器。

该错误意味着您的计算机上没有 ssh。
您可以从任何计算机复制现有的计算机或创建新计算机。


创建并添加 ssh 密钥

来源:https ://help.github.com/en/enterprise/2.15/user/articles/adding-a-new-ssh-key-to-your-github-account

生成 ssh 密钥

  • 打开 Git Bash。

  • 运行ssh-keygen并按照屏幕上的消息进行操作(或者只需单击Enter直到结束)

  • 复制位于以下位置的密钥文件(公钥的内容):

       ~/.ssh/id_rsa.pub
    
    Run Code Online (Sandbox Code Playgroud)

将密钥添加到 Github

  • 在任意页面的右上角,单击您的个人资料照片,然后单击“设置”。 在此输入图像描述

  • 在用户设置侧栏中,单击 SSH 和 GPG 密钥。
    在此输入图像描述

  • 单击“新建 SSH 密钥”或“添加 SSH 密钥”。 在此输入图像描述

  • 将您的密钥粘贴到“密钥”字段中。 在此输入图像描述

  • 单击添加 SSH 密钥。
    在此输入图像描述

  • 将存储库 url 更改为 ssh

      git remote set-url origin <ssh url>
    
    Run Code Online (Sandbox Code Playgroud)