多个位桶帐户
我有一个用于朝九晚五工作的 Bitbucket 帐户,而且我也有一个个人 Bitbucket 帐户。我的目标是能够在同一台计算机上使用两者。我已经在 Windows 7 电脑上安装了最新的 git。
因此,目前我公司 Bitbucket 帐户的一切工作正常,我可以毫无问题地拉/推。我使用 ssh-keygen 创建了一个新的 ssh 密钥,并在我的案例中分配了一个新名称“tech”。但我在如何告诉本地存储库使用我创建的新 ssh 密钥方面遇到了问题。我假设每次尝试连接时都会使用第一个 ssh 密钥。
我收到错误:
$ git push conq:存储库访问被拒绝。 fatal: 远程端意外挂断
我在互联网上找到了一些建议,但它似乎与 linux/git 设置有关,例如我在 Windows 上找不到“config”文件。
I have a Bitbucket account for my 9-5 job and I also have a personal Bitbucket account. My goal is to be able to use both on the same computer. I have installed the latest git on a Windows 7 pc.
So currently everything with my companies Bitbucket account works fine, I can pull/push with no problems. I created a new ssh key using ssh-keygen and assigned a new name in my case "tech". But I am having issues on how to tell a local repo to use the new ssh key I created. I am assuming everytime I try to connect it uses the first ssh key.
I get the error:
$ git push
conq: repository access denied.
fatal: The remote end hung up unexpectedly
I found some advice on the internet but it seems to relate to a linux/git setup, for example I can't find the "config" file on windows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这篇博文介绍了添加多个帐户的简单方法ssh 密钥连接到一台计算机,并为每个 bitbucket 帐户使用一个 ssh 密钥。它比官方 bitbucket 文档清楚得多。总结一下:
首先,确保您通过 Github 上的 此教程设置了默认帐户。
对于第二个帐户:
创建新的 ssh 密钥:
添加 ssh 密钥:
使用
pbcopy < ~/.ssh/<您的第二个帐户名称>.pub
复制公钥并将此密钥添加到您的 bitbucket 帐户(在设置区域中)(在 Windows 上,您可以使用
ssh-keygen -f ~/.ssh/<您的帐户名称> -c “<您的电子邮件>”| 剪辑
或在 Linux 上您可以按照这些说明进行操作。)将以下内容添加到您的
~/.ssh/config
文件中。第一个设置 bitbucket.org 的默认密钥。第二个将您的第二个密钥设置为 bitbucket.org 的别名bitbucket-account2
:您现在可以像以前一样使用默认帐户克隆项目:
要使用第二个身份克隆项目,请将 bitbucket.org 替换为您在
中指定的主机~/.ssh/config
文件(即上面的bitbucket-account2
):就是这样!
This blog post describes a straightforward way to add multiple ssh keys to a single computer and use one ssh key per a bitbucket account. It is much clearer than the official bitbucket documentation. To summarize:
First, make sure you have a default account setup through a tutorial like this one on Github.
For the second account:
Create a new ssh key:
Add the ssh key:
Use
pbcopy < ~/.ssh/<your second account name>.pub
to copy the public key and add this key to your bitbucket account (in the settings area)(On Windows you can copy the ssh key using
ssh-keygen -f ~/.ssh/<your account name> -c "<your email>" | clip
or on Linux you can follow these instructions.)Add the following to your
~/.ssh/config
file. The first sets the default key for bitbucket.org. The second sets your second key to an aliasbitbucket-account2
for bitbucket.org:You can now clone projects with your default account the same way as before:
To clone a project with the second identity, replace bitbucket.org with the Host that you specified in the
~/.ssh/config
file (i.e.bitbucket-account2
above):That's it!
如果您尚未将密钥添加到密钥管理器 (ssh-agent),则可能会收到此错误。为此:
顺便说一句,如果您有多个 Bitbucket 帐户,则每个帐户都需要一个唯一的密钥。您不能重复使用密钥。
You may get this error if you haven't added the key to the key manager (ssh-agent). To do this:
By the way, if you have multiple Bitbucket accounts, you'll need a unique key for each account. You can't reuse keys.
如前所述,您只需要生成一次公钥 - 因为您已经设置了 BitBucket,那么您的 id_rsa (或您命名的任何文件)文件在哪里?在我们的 Windows 安装中,它位于用户主目录下的隐藏文件夹
.ssh
中。您应该能够在那里创建一个config
文件。As stated, you only need to generate your pubkey once - since you're already setup with BitBucket, where is your
id_rsa
(or whatever you named yours) file? On our Windows installs, it's under the user's home directory in the hidden folder.ssh
. You should be able to create aconfig
file there.您应该只生成一次公钥/私钥对。然后,如果您提供私钥,则拥有您的公钥的所有主机都允许您的连接。
You should generate public/private key pair only once. Then all hosts which have your public key do allow connections from you if you provide the private key.
您可以在您的个人 Bitbucket 帐户中添加您的公司电子邮件,在 Bitbucket 帐户管理页面中:
您可以登录您的 Bitbucket 帐户。个人电子邮件帐户,并在单个 bitbucket 帐户中访问个人项目和公司项目,该帐户仅使用一个 ssh 私钥。
You can add your company email in your personal bitbucket account, In bitbucket account manage page:
You can login your personal email account, and access both personal projects and company projects in single bitbucket account, which is using only one ssh private key.