昨天我创建了一个 ssh 密钥并克隆了一个用于工作的存储库。进行一些更改后,我尝试推送提交:
git push
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)
我已经阅读了这篇活跃的 SO 帖子。我的问题仍然存在。我不知道如何找出问题所在,因此将分享我认为相关的所有内容。
在我的笔记本电脑上,我有个人和工作存储库。我的工作工作位于嵌套在~/Documents/Projects/Zen/Projects/. 其他地方例如~/Documents/Projects/Personal/用于个人github。
我的 .gitconfig 看起来像这样:
[user]
email = 12345+doug@users.noreply.github.com
name = 12345doug
[includeIf "gitdir:/home/doug/Documents/Projects/Zen/"]
path = ~/.git-zen
Run Code Online (Sandbox Code Playgroud)
/.git-zen 看起来像这样:
[user]
email = doug@work.com
name = doug-work
Run Code Online (Sandbox Code Playgroud)
目前我在一个仓库中:
pwd
/home/doug/Documents/Projects/Zen/Projects/analytics-psql-action
Run Code Online (Sandbox Code Playgroud)
一些提交准备好推送:
~/Documents/Projects/Zen/Projects/analytics-psql-action$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
Run Code Online (Sandbox Code Playgroud)
我在这个目录中的 git 配置似乎是正确的:
git config user.name
doug-work
Run Code Online (Sandbox Code Playgroud)
和
git config user.email
doug@work.com
Run Code Online (Sandbox Code Playgroud)
为了创建我的 ssh 密钥,我按照github.com 上的这篇文章进行操作。
ssh-keygen -t rsa -b 4096 -C "doug@work.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
Run Code Online (Sandbox Code Playgroud)
然后,我将本教程的密钥添加到我的工作 github 设置中。
到目前为止,我想我已经把一切都设置好了?但是当我尝试从这个仓库中推送时:
~/Documents/Projects/Zen/Projects/analytics-psql-action$ git push
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)
无奈之下,我重命名了该存储库并尝试从新版本中克隆:
git clone git@github.com:work/analytics-psql-action.git # real path actually used not 'work'
Cloning into 'analytics-psql-action'...
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
Run Code Online (Sandbox Code Playgroud)
在存储库本身上,如果我进入存储库设置>管理访问权限,我可以看到自己,doug-work 具有管理员访问权限。
如何克隆并推送到存储库?我应该从哪里开始尝试找出为什么我的 ssh 密钥设置不起作用?
tor*_*rek 13
首先,了解一些背景信息:在此处使用的 URL 中:
git clone git@github.com:...
Run Code Online (Sandbox Code Playgroud)
这个问题唯一真正重要的部分是git@github.com部分。你也可以这样拼写:
git clone ssh://git@github.com/...
Run Code Online (Sandbox Code Playgroud)
(使用完全相同的文本其余部分代替...)具有完全相同的效果。
接下来,要诊断问题ssh,您需要从命令行运行:
ssh -T git@github.com
Run Code Online (Sandbox Code Playgroud)
如果您的 URL 表示git@corp.com您想ssh -T git@corp.com在此处运行,等等。也就是说,我们参与user@host并运行ssh -T user@host。这使得它适用于各种公司托管的分支变体,而不仅仅是 GitHub。它还允许我们在GitHub 上使用多个登录名:请参阅下面的更多信息。
现在,运行后ssh -T git@github.com您可能会收到权限被拒绝错误,这意味着您在 github.com 上尝试过的所有密钥都不起作用,或者您可能会得到这种输出:
Hi M! You've successfully authenticated, but but GitHub does not provide shell access.
Run Code Online (Sandbox Code Playgroud)
(在这里,我们已向 GitHub 验证了自己的身份,即詹姆斯·邦德间谍部门的负责人 M。)
现在,如果 M 有权访问(读取和写入)存储库,我们将能够读取和写入存储库。但也许 M 只有读取权限,而实际上Q具有写入权限。我们偷了 M 和 Q 的钥匙,但是我们如何以 Q 身份进入呢?
在我们讨论这一点之前,让我们看看如果这种身份验证完全失败该怎么办。我们的下一步是运行:
ssh -Tv git@github.com
Run Code Online (Sandbox Code Playgroud)
这会产生大量输出,所有输出都以debug1. 这里可能有一些线索可以说明出了什么问题。如果没有,我们可以使用ssh -Tvv, 或ssh -Tvvv, 来获得更多调试输出,并以debug2和为前缀debug3。查看所有这些输出时,通常的怀疑是确保 ssh 正在查看存储您的 ssh 密钥的正确.ssh/* 文件。确保:
如果没有,请寻找特定于操作系统的方法来为 ssh 提供正确的权限和/或路径。
当邪恶的间谍闯入军情五处的记录时,我们已经泄露了 M 和 Q 的密钥,现在我们希望将我们的特洛伊木马插入系统,以便我们可以尝试对詹姆斯·邦德进行过于精心设计的死亡。但这是以后的事了:现在,我们以 M 身份进入,但我们需要以 Q 身份进入。我们该怎么办?
为了以Q而不是M 的身份进入 GitHub ,我们需要正确配置 ssh。原因很简单:仅仅列出目录中的所有密钥.ssh是行不通的。ssh 按某种顺序尝试它们,显然,我们的 ssh 首先尝试我们的M键。一旦起作用,它就进入了,并且 ssh 停止尝试更多的密钥。
我们需要让 ssh 首先尝试我们的Q键。我们可以删除M 的密钥,但这很烦人:现在我们可以植入特洛伊木马,但我们找不到 Bond 的当前任务,该任务只能由 M 读取。我们想要的是一种选择的方法我们将尝试使用哪个键。
这就是.ssh/config文件的来源:
Host as-q
Hostname github.com
User git
IdentitiesOnly yes
IdentityFile ~/.ssh/stolen-q-key
Host as-m
Hostname github.com
User git
IdentitiesOnly yes
IdentityFile ~/.ssh/stolen-m-key
Run Code Online (Sandbox Code Playgroud)
现在我们可以将两个存储库列为ssh://as-m/mi5/bond-assignments.git和ssh://as-q/mi5/spy-devices.git,或as-m:mi5/bond-assignments.git和as-q:mi5/spy-devices.git。(也就是说,一旦你让这部分工作,你将需要更新与你的克隆相关的 URL。使用或或任何你最喜欢的方式来实现这一点。)git remote set-url origin new-urlgit config --edit
当我们这样做时ssh as-q,我们将通过 ssh 连接到 github.com ( Hostname),使用git作为用户名,并使用窃取的 Q 密钥作为密钥。当我们 时ssh as-m,我们将连接到同一主机并使用同一用户,但这次使用被盗的M密钥。
您还遇到了另一个问题:
如果系统 ssh 工作正常,请告诉 Git 使用系统 ssh,例如git config --global core.sshCommand ssh. 如果不够,请使用捆绑的 ssh(但是上面的测试是如何工作的?)。
| 归档时间: |
|
| 查看次数: |
27792 次 |
| 最近记录: |