我上传了我的~/.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——


当前回答

我用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/*
        ...
        ...
        ...

其他回答

我用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/*
        ...
        ...
        ...

实际上,这些答案都没有反映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)和您生成的应用程序密码作为密码。

我用我的用户名而不是电子邮件登录,它开始工作。

您确定您使用ssh url克隆了它吗?

url的来源说url = https://Nicolas_Raoul@bitbucket.org/Nicolas_Raoul/therepo.git,所以如果它是使用https,它会要求密码,不管你的ssh密钥。

所以你要做的是:

在当前的repo中打开配置文件。

一个git / problem。

并更改包含url的行

[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = https://Nicolas_Raoul@bitbucket.org/Nicolas_Raoul/therepo.git

to

[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = git@bitbucket.org:Nicolas_Raoul/therepo.git

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

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

这样就省去了每次都要提交你的证书的麻烦。简单地修改你的.git/config (url)。