英文:
SSH config using wrong key?
问题
我今天开始了一份新工作,在那里他们使用Bitbucket,并为我使用了我的新工作邮箱地址创建了一个帐户。
然而,当我粘贴我的SSH密钥时,Bitbucket 抱怨说该密钥已经在使用(我的个人帐户),因此我不得不设置另一个密钥。
我的SSH配置看起来像这样,但它不起作用,似乎选择了错误的密钥:
主机 work
主机名 bitbucket.org
用户 git
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_work
IdentitiesOnly yes
主机 *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
然后我尝试 git clone work:path/to/some.git
,但得到了 "无法从仓库读取" 的错误消息。
在它能够工作之前,我不得不编辑掉我的普通 id_rsa
,所以现在它看起来像这样:
主机 *
主机名 bitbucket.org
用户 git
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_work
IdentitiesOnly yes
我做错了什么?
英文:
I started in a new job today, where they use bitbucket, and they have created me an account using my new work email address.
However, when I pasted my SSH key in, Bitbucket complained that the key was already in use (my personal account), so I had to set up another key.
My SSH config looked like this, but it didn't work and seemed to pick up the wrong key:
Host work
HostName bitbucket.org
User git
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_work
IdentitiesOnly yes
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
then I tried git clone work:path/to/some.git
but got "could not read from repo."
I had to edit away my normal id_rsa
before it would work, so now it looks like this:
Host *
HostName bitbucket.org
User git
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_work
IdentitiesOnly yes
What did I do wrong?
答案1
得分: 3
使用您的初始配置文件(其中包含Host work
和Host *
),您可以执行以下操作:
ssh -Tv work
您将看到实际使用的密钥。如果是id_rsa
,那意味着Host *
中指定的内容优先于Host work
。
如果您想要除了工作之外的所有情况都使用您的个人密钥,您需要使用一个模式来实现:
Host * !work
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
<details>
<summary>英文:</summary>
Using your initial config file (the one with `Host work` and `Host *`), you can do a
ssh -Tv work
You will see what key is actually used. If it is `id_rsa`, that means what is specified in `Host *` takes precedence over `Host work`.
If you want to [use your personal key for everything *except* work][1], you would need to [use a pattern][2]:
Host * !work
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
[1]: https://superuser.com/a/732274/141
[2]: http://man.openbsd.org/OpenBSD-current/man5/ssh_config.5#PATTERNS
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论