git - 无法使用别名获取多个 ssh key 以与 BitBucket 一起使用

标签 git ssh bitbucket ssh-keys ssh-keygen

我有两个 bitbucket 帐户,一个用于个人资料,一个用于工作。我个人的工作正常,我在工作中使用的也工作正常;但是,我希望能够在家中连接到工作,但无法使其正常工作。

我的文件名为:

## Unrelated ones I use for plan.io that still work

id_rsa
id_rsa.pub

## Personal one for bitbucket I just created because of seperation

homeid
homeid.pub

## Work one for bitbucket

workid
workid.pub

我的配置文件是:
Host home@bitbucket.org
 HostName bitbucket.org
 IdentityFile ~/.ssh/homeid


Host work@bitbucket.org
 HostName bitbucket.org
 IdentityFile ~/.ssh/workid

现在我对如何使用别名进行克隆有点困惑,但尝试了:
git clone work@bitbucket.org:my-username/myrepo.git

但它失败并显示错误消息:
Cloning into 'myrepo'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我已将公钥添加到相应的 bitbucket 帐户中,所以不确定我在这里做错了什么?

最佳答案

好的,解决了。

我使用了不正确的 git clone 地址,正确的是:

git clone git@workid:my-username/myrepo.git

...但还必须将我的配置文件更改为以下内容以更改主机:
Host homeid
 HostName bitbucket.org
 IdentityFile ~/.ssh/homeid


Host workid
 HostName bitbucket.org
 IdentityFile ~/.ssh/workid

关于git - 无法使用别名获取多个 ssh key 以与 BitBucket 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39413198/

相关文章:

GitLab CI 与 Jenkins

ruby-on-rails - ExecJS::RuntimeError: SyntaxError: 意外的标记:运算符 (>) (行:22342,列:24,位置:826182)

Git - 从 .git 文件夹中删除文件而不远程删除它

android - Gradle 模块和 git 子模块

python - Amazon EC2 微型实例不响应 'which python' 命令

linux - Emacs shell 模式 SSH session 中的 Tab 补全

git - OS X上的Git-CodeCommit URL问题

.net-core - Bitbucket Pipeline/.Net Core - 项目文件不存在

git - 在 Bitbucket 中,什么是 "active"分支,许多 "active"分支的影响是什么?

svn - 当主干/分支/标签结构一团糟时,如何从 Subversion 迁移到 Mercurial?