无法推送到我的 github 私有存储库

use*_*697 5 linux git ssh github ssh-keys

在学习 git 时,我在GitHub 上建立了一个私有存储库。我已经创建了 ssh 密钥并将其存储到我的 GitHub 帐户并在我的本地 Linux 机器上编辑了 .ssh/config 文件:

    ## github
        Host github.com
        User git
        HostName github.com
        IdentityFile ~/.ssh/github.key
Run Code Online (Sandbox Code Playgroud)

我可以成功连接到我的 GitHub 帐户:

    $ ssh -T github
    Hi <UserName>! You've successfully authenticated, but GitHub does not provide shell access.
Run Code Online (Sandbox Code Playgroud)

我已经在本地机器上初始化了一个 git 存储库,设置了用户并添加了一个远程存储库:

    $ git init
    $ git config user.name "UserName"
    $ git config user.email "UserEmail"
    $ git remote add origin ssh://github:<UserName?/<repositoryName>.git
Run Code Online (Sandbox Code Playgroud)

我创建了一个README.md文件,将其添加到 git 并提交:

    $ git add README.md
    $ git commit -m "First commit."
Run Code Online (Sandbox Code Playgroud)

现在,每次我尝试推送时,都会收到此错误:

    $ git push origin master

    ERROR: Repository not found.
    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)

克隆存储库有效,但这是我唯一能做的事情。

为什么我不能推送到我的私人存储库?我究竟做错了什么?

Von*_*onC 5

尝试使用scp 语法,以确保使用您的~/.ssh/config文件:

git remote set-url origin github:<username>/<repo>
Run Code Online (Sandbox Code Playgroud)

然后再次尝试推动。


Git 本身使用 OpenSSH 版本(至少是一个带有Git for Windows 的包)

> ssh -V
OpenSSH_7.5p1, OpenSSL 1.0.2k  26 Jan 2017
Run Code Online (Sandbox Code Playgroud)

如“为什么 ssh 命令不遵循 URI 上的 RFC? ”中所述,两者之间存在差异:

ssh://[user@]host.xz[:port]/path/to/repo.git
vs.
user@host.xz:/path/to/repo.git
Run Code Online (Sandbox Code Playgroud)

只有后一种语法user@host.xz:使用ssh 配置文件

最初开发 SSH 时,它被开发为更安全的直接替代早期的 RSH/rlogin 工具套件。

请参阅“ SSH 协议的历史”。

OpenSSH (1999) 早于URI(在RFC 3986 中最终确定,于 2005 年 1 月发布)

如果允许主机部分出现在表单上host:port,这将产生潜在的歧义:在标准端口上连接时是否jdoe@host.example.com:2222引用~jdoe/2222on host.example.com,或者在通过端口 2222 连接时根本不引用任何文件(或更糟的是,~jdoeon)host.example.com?