git - 推送到 github 时 Git 未使用正确的 SSH 密钥
问题描述
所以我有两个不同的 github 帐户,我为它们创建了两个不同的 SSH 密钥id_me
,id_work
但是当我尝试从我的工作帐户进行 git 推送时,它会使用我的个人 SSH 密钥对我进行身份验证。
这就是我所做的:
将每个 SSH 密钥添加到其各自的 github 帐户。然后按照步骤将它们添加到我的 SSH 代理:
ssh-add -K id_me
ssh-add -K id_work
并像这样设置我~/.ssh/config
:
# Personal github account
Host github.com
HostName github.com
User git
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_me
# Work github account
Host github.com-work
HostName github.com
User git
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_work
我正在尝试对我的工作帐户上的存储库进行一些更改。首先,我确保使用正确的命令克隆它:
git clone git@github.com-work:test.git
但是,当我将更改推送回来时,它会引发权限被拒绝错误消息:
ERROR: Permission to test.git denied to doctopus.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
另外,我注意到当我运行时ssh -T github.com-work
,它会在我的个人帐户上对我进行身份验证:
Hi doctopus! You've successfully authenticated, but GitHub does not provide shell access.
所以问题看起来像 git 在推送到 github 时没有使用正确的 SSH 密钥。
解决方案
ssh -Tv github.com-work
将显示实际使用的键。
这样,您可以验证您的 ~/.ssh/config 内容。
仔细检查注册到您的 GitHub 帐户的公钥的内容,以及两个公钥 (id_work.pub
和id_me.pub
)的内容
推荐阅读
- javascript - 如何为 jsPDF 文档添加边距?
- c# - 填充面板作为进度条
- react-native - 在 React-Native 应用程序中加载 jsPDF 时出错
- python - 数据框字典选择数据框的名称
- c# - 适用于 chrome、firefox 和 safari 浏览器的 Azure 浏览器推送通知
- javascript - 如何使用电子菜单执行 Angular 7 导航
- python - Google Cloud Platform,ML 引擎,没有名为 sklearn_crfsuite.estimator 的模块
- qt - 连接来自 QVector 中小部件的信号
- css - 适用于 iPhone 和 Android 手机的 CSS 等效于 srcset(x 描述符)
- bash - 使用 Bash 脚本自动将 360° 3D 元数据注入视频