如何使用 SSH 将我的存储库推送到 GitHub? [英] How can I use SSH to push my repository to GitHub?

查看:41
本文介绍了如何使用 SSH 将我的存储库推送到 GitHub?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

为什么

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

我做了什么

我将 kaede0902/php 的远程 url 设置为 htdocs/workspace,并试图拉.我用过 sudo.

错误信息

kaede@kaede-ThinkPad-T450:/opt/lampp/htdocs/workspace$ sudo git pull origin master警告:已将 IP 地址52.69.186.44"的 RSA 主机密钥永久添加到已知主机列表中.git@github.com:权限被拒绝(公钥).致命:无法从远程存储库读取.请确保您拥有正确的访问权限并且存储库存在.

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

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

有什么问题?

解决方案

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

该错误表示您的机器上没有 ssh.
您可以从任何一台机器复制现有的机器或创建一台新机器.

<小时>

创建和添加 ssh 密钥

来源:

  • 在用户设置侧栏中,单击 SSH 和 GPG 密钥.

  • 单击新建 SSH 密钥或添加 SSH 密钥.

  • 将您的密钥粘贴到密钥"字段中.

  • 点击添加 SSH 密钥.

  • 将存储库 url 更改为 ssh

    git remote set origin 

  • How can I push my repository to Github using SSH?

    Why

    I want to host my repository on GitHub during my PHP study.

    What I did

    I set remote url of kaede0902/php to htdocs/workspace, and tried to pull. I used sudo.

    Error Message

    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.
    

    My ssh url is git@github.com:kaede0902/php.git.

    I am using ssh connection for other repos.

    What is the problem?

    解决方案

    You have to add your ssh key to both machines.

    The error means that you don't have the ssh on your machine.
    You can copy the existing one form any of your machines or create a new one.


    Creating and adding ssh key

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

    Generating ssh key

    • Open Git Bash.
    • Run ssh-keygen and follow the on-screen messages (or simply click Enter till it over)
    • Copy the key file (the content of the public key) located in:

       ~/.ssh/id_rsa.pub
      

    Add key to Github

    • In the upper-right corner of any page, click your profile photo, then click Settings.

    • In the user settings sidebar, click SSH and GPG keys.

    • Click New SSH key or Add SSH key.

    • Paste your key into the "Key" field.

    • Click Add SSH key.

    • change the repository url to ssh

      git remote set origin <ssh url>
      

    这篇关于如何使用 SSH 将我的存储库推送到 GitHub?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆