简体   繁体   English

无法通过SSH进入我的Bitbucket存储库-确认:存储库访问被拒绝

[英]Can't SSH into my Bitbucket repository - conq: repository access denied

I have followed a million guides regarding this and I cannot get it to work. 我已经按照一百万的指南对此进行了操作,但我无法使其正常工作。 Earlier, I successfully pushed via SSH to my private Bitbucket git repository, now suddenly it wont work. 之前,我通过SSH成功​​推送到了我的私有Bitbucket git存储库,现在突然不起作用了。

I have recreated the keys with a new passphrase, added it to my Bitbucket settings and it wont work. 我用新的密码短语重新创建了密钥,并将其添加到我的Bitbucket设置中,它将无法正常工作。

Okay, here are the steps I took: 好的,这是我采取的步骤:

  1. Deleted old key pair (project1 and project1.pub) 删除旧密钥对(project1和project1.pub)
  2. Recreated it with this command ssh-keygen -f ~/.ssh/project1 -C "project1" 使用此命令重新创建它ssh-keygen -f ~/.ssh/project1 -C "project1"
  3. Created a config in ~/.ssh file for my two Bitbucket accounts, with the following contents: ~/.ssh文件中为我的两个 Bitbucket帐户创建了一个config ,内容如下:

Host project1 HostName bitbucket.org IdentityFile ~/.ssh/project1 Host project2 HostName bitbucket.org IdentityFile ~/.ssh/project2

  1. Grabbed the contents of project1.pub and created a new SSH key entry in my Bitbucket account. 抓住project1.pub的内容,并在我的Bitbucket帐户中创建了一个新的SSH密钥条目。
  2. Added ssh-agent in my ~/.zshrc plugin list like this: plugins=(git ssh-agent) and restarted Terminal 在我的~/.zshrc插件列表中添加ssh-agent ,如下所示: plugins=(git ssh-agent)并重新启动终端
  3. Did ssh-add -l and saw only project2 was loaded ssh-add -l并只加载了project2
  4. Did ssh-add ~/.ssh/project1 , entered my passphrase and success, like this: ssh-add ~/.ssh/project1输入了我的密码并成功,如下所示:

2048 SHA256:THESHA256 /Users/myuser/.ssh/project2 (RSA) 2048 SHA256:THESHA256 /Users/myuser/.ssh/project1 (RSA)

  1. Restarted Terminal and did ssh-add -l and it listed both entries 重新启动终端并执行ssh-add -l并列出了两个条目
  2. Went to my project and did git push and it told me I had no access. 进入我的项目并进行git push ,它告诉我我无法访问。

When I do ssh -T git@bitbucket.com , it tells me I'm logged in with the username of project2 . 当我执行ssh -T git@bitbucket.com ,它告诉我我使用project2的用户名登录

logged in as project2_user. 以project2_user身份登录。

My system is OS X 10.11.5 我的系统是OS X 10.11.5

I could never fix multiple identities on my computer and always used HTTPS, but I need to make everything more secure with SSH, which also allows my account to have two-factor authentication. 我永远无法在计算机上修复多个身份,并且始终使用HTTPS,但是我需要使用SSH来确保所有内容的安全,这也使我的帐户具有两重身份验证。 Therefore using SSH is a must now and I don't know what to do. 因此,现在必须使用SSH,我不知道该怎么办。

PS: I did the creating steps for the identity for project2 too, but I'm fairly certain that it doesn't work either. PS:我也为project2的身份做了创建步骤,但是我相当确定它也不起作用。


Guide I followed: 我遵循的指南:

https://confluence.atlassian.com/bitbucket/configure-multiple-ssh-identities-for-gitbash-mac-osx-linux-271943168.html https://confluence.atlassian.com/bitbucket/configure-multiple-ssh-identities-for-gitbash-mac-osx-linux-271943168.html


EDIT 编辑

project2 has no passphrase, while project1 does! project2没有密码,而project1有! Just thought maybe this is relevant. 只是认为这可能是相关的。

EDIT 2 编辑2

I did ssh-add -D to remove all loaded keys, then added the key for project1 , entered passphrase and pushed. 我做了ssh-add -D删除了所有已加载的密钥,然后为project1添加了密钥,输入了密码并推送了它。 It worked. 有效。 But now my other identity is not working because its key is not loaded. 但是现在我的其他身份不起作用,因为未加载其密钥。

Why aren't my multiple identities working? 为什么我的多个身份不起作用?

If different repositories on the same remote host require usage of different SSH identities then you must use SSH aliases. 如果同一远程主机上的不同存储库要求使用不同的SSH身份,则必须使用SSH别名。

Check that remote.origin.url has the following (or equivalent) values in your local repositories: 检查remote.origin.url在本地存储库中remote.origin.url具有以下(或等效值)值:

  • project1 : git@bitbucket.org:accountX/project1.git project1git@bitbucket.org:accountX/project1.git
  • project2 : git@bitbucket.org:accountY/project2.git project2git@bitbucket.org:accountY/project2.git

accountX may be either your account associated with your 1st identity on Bitbucket (ie project1_user ), or another account that has granted access to project1_user to their repository project1 . accountX可以是与您在Bitbucket上的第一个身份相关联的帐户(即project1_user ),也可以是向其存储库project1授予对project1_user访问权的另一个帐户。 The same goes for project2 . project2

Now, when git has to connect to the remote repository from your local repository, it will first have to connect to the remote server, and the latter for your both projects is set to bitbucket.org . 现在,当git必须从本地存储库连接到远程存储库时,它将首先必须连接到远程服务器,并且这两个项目的后者都设置为bitbucket.org Then, how does git know which SSH identity to use? 然后,git如何知道要使用哪个SSH身份? It picks some identity associated with bitbucket.org . 它选择一些bitbucket.org相关的身份。

Update your remote.origin.url settings as follows: 如下更新您的remote.origin.url设置:

  • project1 : git@project1:accountX/project1.git project1git@project1:accountX/project1.git
  • project2 : git@project2:accountY/project2.git project2git@project2:accountY/project2.git

Then, when git is told to connect to git@project1 , it resolves project1 to the corresponding entry in ~/.ssh/config and uses the identity specified therein. 然后,当告诉git连接到git@project1 ,它将project1解析为~/.ssh/config的相应条目,并使用其中指定的标识。 Similarly for project2 . 对于project2同样。

Basing on my experience you can save yourself lot of time and efforts using HTTPS in this circumstance. 根据我的经验,在这种情况下,您可以节省大量时间和精力使用HTTPS。

I'd not success with multiple SSH identities few months ago. 几个月前,我无法通过多个SSH身份获得成功。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM