我上传了我的~/.ssh/id_rsa。但是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

在相同的环境下,使用相同的公钥,Github上的Git可以正常工作。 . ssh rwx -, . ssh / id_rsa - r -------, . ssh / id_rsa。Pub是-rw-r——r——


当前回答

实际上,这些答案都没有反映Git的当前技术状态(在撰写本文时是v2.29)。在最新版本的Git中,cache、winstore、wincred已弃用。


如果你想通过HTTPS克隆一个Bitbucket存储库,例如。

Git 克隆 https://Kutlime@bitbucket.org/SomeOrganization/SomeRepo.git

你必须:

在Bitbucket用户管理中生成应用程序密码。 相应地在.gitconfig中设置凭据方法(全局或本地)

[credential]
    helper = manager

您可以通过执行此命令找到您的.gitconfig。

git config --list --show-origin

执行

git clone https://Kutlime@bitbucket.org/SomeOrganization/SomeRepo.git

并等待,直到登录窗口出现。使用url中的用户名(在我的例子中是kutlime)和您生成的应用程序密码作为密码。

其他回答

上面已经回答了。我将总结上述检查步骤。

在项目目录下运行git remote -v。如果输出显示以https://abc开头的远程url,那么您可能每次都需要用户名和密码。

因此,要更改远程url,请运行git remote set-url origin {ssh远程url地址以git@bitbucket.org:}开头。

现在运行git remote -v来验证修改后的远程url。

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

这些答案都帮不了我,结果我的问题有点不同。ssh每次都在发送密钥之前询问我的密码。所以我要做的就是把我的密码和这个命令链接起来:

ssh-add -K ~/.ssh/id_rsa

然后它会提示您输入密码并存储密码。这可能是你正在寻找的解决方案,如果每次提示输入密码时,它会说

输入密钥'/Users//.ssh/id_rsa'的密码:

更多信息请点击这里

注意:我在我的mac机器上成功地使用了这个选项,但正如@Rob Kwasowski在下面指出的那样,大写K选项是mac独有的。如果不是在mac上,你将需要使用小写K(这可能也适用于mac,但我还没有测试)。

步骤1:安装git-credential-winstore https://confluence.atlassian.com/bitbucketserver/permanently-authenticating-with-git-repositories-776639846.html 步骤2:git配置——global credential。Helper '缓存超时3600' 这将存储您的密码1小时 步骤3:执行git命令 这将提示您输入密码,并提示凭据 并保存密码

如果你仍然得到太多的身份验证失败错误:

nano ~/.ssh/config

粘贴:

Host bitbucket_james
    HostName bitbucket.org
    User james
    Port 22
    IdentitiesOnly=yes
    IdentityFile=~/.ssh/id_rsa_bitbucket_james

最重要的是-你应该bitbucket_james的别名而不是bitbucket.org当你设置你的远程URL:

git remote set-url origin git@bitbucket_james:repo_owner_user/repo_name.git

我用HTTPS URL克隆了存储库,而不是SSH URL,因此即使在添加SSH密钥后,它也在Bash Shell上询问我的密码。

我只是编辑了。/。并通过简单地将https://替换为ssh://来改变url变量的值

E.g.

[core]
        ...
        ...
        ...
[remote "origin"]
        url = https://<username>@bitbucket.org/<username>/<repository_name>.git
        fetch = +refs/heads/*:refs/remotes/origin/*
        ...
        ...
        ...

更改为:

[core]
        ...
        ...
        ...
[remote "origin"]
        url = ssh://<username>@bitbucket.org/<username>/<repository_name>.git
        fetch = +refs/heads/*:refs/remotes/origin/*
        ...
        ...
        ...