git - mac 超时时 git 的 ssh 配置文件
问题描述
我有 2 个要与 Github 一起使用的帐户,我正在尝试按照本教程将 github 设置为通过 ~/.ssh/config 处理多个帐户。我创建了 2 个 ssh 密钥(例如 rsa_1 和 rsa_2)并像这样设置 ~/.ssh/config 文件:
Host github.com
HostName github.com
User username1
IdentityFile ~/.ssh/id_rsa_1
IdentitiesOnly yes
Host work.github.com
HostName github.com
User username2
IdentityFile ~/.ssh/id_rsa_2
IdentitiesOnly yes
然后,我在要与另一个帐户一起使用的 repo 上设置远程 url
git remote set-url origin work.github.com:<shared_gitrepo_name>/project.git
但是当我 git push origin 时,它总是超时
ssh: connect to host work.github.com port 22: Operation timed out
fatal: Could not read from remote repository.
这让我觉得配置文件没有被引用。我不确定我做错了什么。任何帮助,将不胜感激!
解决方案
在这两种情况下,您都使用了错误的用户名:
Host github.com
HostName github.com
User git <==========================
IdentityFile ~/.ssh/id_rsa_1
IdentitiesOnly yes
Host work.github.com
HostName github.com
User git <==========================
IdentityFile ~/.ssh/id_rsa_2
IdentitiesOnly yes
git
您总是要求以用户“ ”而不是用户“ ”的身份与 github.com 建立 SSH 会话usernamex
。
您的公钥被复制到 SSH 个人资料页面这一事实username1
足以username2
让GitHub 知道您是谁。
但是,正如评论中的phd所指出的,超时可能表明存在网络连接问题(例如防火墙阻止了端口 22 上的传出流量)。
即使这样有效,那么错误的用户无论如何都会使 ssh 调用失败。
注意:如讨论中所见,不要使用sudo
Usingsudo
手段,只会/etc/shh/config
考虑,而不是~/.ssh/config
推荐阅读
- python - while cond == None & if cond is None 之间有什么区别?
- tensorflow - 多处理读取tfrecord的DataLossError
- github - Github 代码显示错误的缩进问题
- pdf - 转换为 PDF 时 pandoc 和 jupyter 实验室中的 Markdown 错误
- python - Python 3 - 在链表中使用递归
- asp.net-web-api - 如何在 ASP.NET WebApi 中更改 Swagger 的基本 url
- java - @OneToOne 映射删除然后插入而不是更新
- c++ - 将派生的 QList 转换为基的 QList
- c - rand() 函数在 C 中不能按预期工作
- api - curl中的双重基本身份验证