更改登录为SSH到Bitbucket

时间:2017-01-26 17:45:12

标签: git macos bitbucket

我正在使用Bitbucket进行版本控制,但最近我无法提取或推送提交。我收到错误:

conq: repository access denied.
fatal: Could not read from remote repository.

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

所以在环顾四周后,我发现并运行了ssh -T hg@bitbucket.org命令,显示我以另一个用户身份登录,说userX

UserX是我的个人帐户用户名。我尝试处理的计算机和帐户是公司帐户UserY。不知何故,我设法记录了我的个人帐户。

如果我运行git config --global user.namegit config --global user.email,则会显示正确的工作详情。

有谁知道如何更改"登录为"所以我可以连接到Bitbucket?

由于

1 个答案:

答案 0 :(得分:0)

你必须在bitbucket中设置ssh密钥。

  • 生成ssh-keys

    <=1
  • 现在复制公钥并将其保存在您的bitbucket帐户

    # generate ssh keys. if you have any don't overwrite
    > ssh-keygen 
    
    Generating public/private rsa key pair.
    Enter file in which to save the key (/Users/emmap1/.ssh/id_rsa):
    Created directory '/Users/emmap1/.ssh'.
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /Users/emmap1/.ssh/id_rsa.
    Your public key has been saved in /Users/emmap1/.ssh/id_rsa.pub.
    The key fingerprint is:
    4c:80:61:2c:00:3f:9d:dc:08:41:2e:c0:cf:b9:17:69 emmap1@myhost.local
    The key's randomart image is:
    +--[ RSA 2048]----+
    |*o+ooo.          |
    |.+.=o+ .         |
    |. *.* o .        |
    | . = E o         |
    |    o . S        |
    |   . .           |
    |     .           |
    |                 |
    |                 |
    +-----------------+
    
  • 转到您的bitbucket帐户,在您的gravatar下打开菜单,您会看到> cat ~/.ssh/id_rsa.pub 部分

  • 添加新密钥并将密钥粘贴到文本框

enter image description here

  • 如果使用https而非ssh

  • ,则将现有的repo从HTTPS更改为SSH协议
  • 尝试SSH KEYS并在提示您将密钥添加到知道主机文件时回答“是”。