首页 文章

Git on Bitbucket:即使在上传我的公共SSH密钥后,也总是要求输入密码

提问于
浏览
141

我将 ~/.ssh/id_rsa.pub 上传到Bitbucket's SSH keys作为explained,但是Git仍然要求我在每次操作时输入密码(例如 git pull ) . 我错过了什么?

它是一个私有存储库(另一个人的私有存储库的分支),我克隆它像这样:

git clone git@bitbucket.org:Nicolas_Raoul/therepo.git

这是我当地的 .git/config

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = https://Nicolas_Raoul@bitbucket.org/Nicolas_Raoul/therepo.git
[branch "master"]
        remote = origin
        merge = refs/heads/master

在具有相同公钥的相同环境中,Gitub上的Git工作正常 .
.sshrwx------.ssh/id_rsa-rw-------.ssh/id_rsa.pub-rw-r--r--

9 回答

  • 22

    你确定你使用ssh url克隆它吗?

    原始网址为 url = https://Nicolas_Raoul@bitbucket.org/Nicolas_Raoul/therepo.git ,因此如果使用https,则无论您使用ssh密钥,它都会要求输入密码 .

  • 0

    正如here所述,如果使用 SSH url进行克隆,则每次推/拉时, don't 都需要输入用户名/密码 . 查看@manojlds上面的answer

    但是如果你想用 HTTPS 克隆并希望每次输入用户名/密码 avoid ,你可以使用以下命令将凭证存储到 cache 中:

    git config --global credential.helper 'cache --timeout 3600'

    其中3600(秒)表示1小时,您可以根据您的要求进行更改 .

  • 9

    它已经在上面回答了 . 我将总结上面要检查的步骤 .

    在项目目录中运行 git remote -v . 如果输出显示以 https://abc 开头的远程URL,则每次都可能需要用户名密码 .

    所以要更改远程URL运行 git remote set-url origin {ssh remote url address starts with mostly git@bitbucket.org:} .

    现在运行 git remote -v 以验证更改的远程URL .

    参考:https://help.github.com/articles/changing-a-remote-s-url/

  • 4

    在HTTP请求的情况下,也可以将凭证(带密码)直接粘贴到URL中:

    http://username:password@bitbucket.org/...
    

    这将节省痛苦,每次再次提供您的凭据 . 简单修改你的.git / config(url) .

  • 16

    你好未来的Google员工 .

    在MacOS> = High Sierra上,SSH密钥不再保存到KeyChain because of reasons .

    使用 ssh-add -K 也不再能够重新启动 .

    这是3 possible solutions .

    我've used the first method successfully. I' ve在 ~/.ssh 中创建了一个名为 config 的文件:

    Host *
      AddKeysToAgent yes
      UseKeychain yes
      IdentityFile ~/.ssh/id_rsa
    
  • 1
  • 210

    以下假设通过iTerm / Terminal对bitbucket进行命令行访问 .

    对于 MacOS Sierra 10.12.5,我的系统表现出一个同等的问题 - 在每个与bitbucket的连接上要求我的SSH密码 .

    该问题与macOS 10.12.2中的OpenSSH更新有关,这些更新在Technical Note TN2449中进行了描述 .

    您很可能想要定制您的解决方案,但是当添加到〜/ .ssh / config文件时,以下内容将起作用:

    Host *
        UseKeychain yes
    

    有关ssh配置的更多信息,请查看ssh_config的手册页:

    % man ssh_config
    

    另一件事: superuser here上有一篇很好的文章,根据您的需求和设置讨论了这个问题和各种解决方案 .

  • 6

    您可能需要仔细检查SSH身份文件 . 你可能会指导BitBucket查看你在BitBucket上保存的等效公钥的不同/不正确的私钥 .

    tail ~/.ssh/config 检查 - 你会看到类似于:

    Host bitbucket.org
     HostName bitbucket.org
     IdentityFile ~/.ssh/personal-bitbucket-ssh-key
    

    请记住,可以使用 ssh-add 命令添加其他身份(例如工作和家庭),例如:

    ssh-keygen -t rsa -C "companyName" -f "companyName"
    ssh-add ~/.ssh/companyName
    

    一旦确认在本地查找了哪个私钥,就可以使用公共等效项,在这种情况下:

    cat ~/.ssh/personal-bitbucket-ssh-key.pub | pbcopy
    

    并将该密码粘贴到BitBucket上 . 你的git推送现在(如果你正在使用SSH克隆,正如前面提到的答案所指出的那样)在没有密码的情况下被允许,因为你的设备是公认的友好 .

    希望这有助于为某人清除它 .

  • 2

    和我一起,虽然我运行'git clone ssh://git@stash.xxx.com:7999 / projName / projA.git'我仍然被提示输入我克隆的这个新repo的密码,所以通过比较它.git / config文件到其他工作的repos,它原来是[remote“origin”]部分下的url,它被设置为上面的ssh路径用于新的repo,但是设置为https:xxx用于工作的 .

相关问题