【问题标题】:Cannot push to my github private repository无法推送到我的 github 私有存储库
【发布时间】:2018-05-02 07:02:54
【问题描述】:

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

    ## github
        Host github.com
        User git
        HostName github.com
        IdentityFile ~/.ssh/github.key

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

    $ ssh -T github
    Hi <UserName>! You've successfully authenticated, but GitHub does not provide shell access.

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

    $ git init
    $ git config user.name "UserName"
    $ git config user.email "UserEmail"
    $ git remote add origin ssh://github:<UserName?/<repositoryName>.git

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

    $ git add README.md
    $ git commit -m "First commit."

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

    $ 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.

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

为什么我不能推送到我的私有仓库?我做错了什么?

【问题讨论】:

  • 输入git remote -v会得到什么
  • 我收到与push 命令相同的错误。

标签: linux git github ssh ssh-keys


【解决方案1】:

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

git remote set-url origin github:<username>/<repo>

然后再次尝试推送。


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

> ssh -V
OpenSSH_7.5p1, OpenSSL 1.0.2k  26 Jan 2017

如“Why doesn't the ssh command follow RFC on URI?”中所述,两者之间存在差异:

ssh://[user@]host.xz[:port]/path/to/repo.git
vs.
user@host.xz:/path/to/repo.git

只有后一种语法user@host.xz: 使用ssh config file

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

见“History of the SSH protocol”。

OpenSSH (1999) 早于URI(定稿于RFC 3986,2005 年 1 月发布)

如果允许主机部分采用host:port 形式,这将产生潜在的歧义:在标准端口上连接时,jdoe@host.example.com:2222 是指host.example.com 上的~jdoe/2222,还是指通过端口 2222 连接时,host.example.com 上根本没有文件(或更糟糕的是,~jdoe)?

【讨论】:

  • 工作就像一个魅力。接受并赞成。你能解释一下为什么它不适用于ssh://吗?
  • @user44697 第一个 ssh://host:port/path 遵循 URI 方案,但 ssh 早于 URI:unix.stackexchange.com/a/75672/7490
猜你喜欢
  • 2019-06-18
  • 2021-11-27
  • 2021-08-22
  • 2021-09-11
  • 2017-08-22
  • 1970-01-01
  • 2021-09-28
  • 2011-12-09
  • 2023-03-03
相关资源
最近更新 更多