Warm tip: This article is reproduced from serverfault.com, please click

Git on Bitbucket: Always asked for password, even after uploading my public SSH key

发布于 2011-12-22 07:28:48

I uploaded my ~/.ssh/id_rsa.pub to Bitbucket's SSH keys as explained, but Git still asks me for my password at every operation (such as git pull). Did I miss something?

It is a private repository (fork of another person's private repository) and I cloned it like this:

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

Here is my local .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

In the same environment with the same public key, Git on Github works fine.
.ssh is rwx------, .ssh/id_rsa is -rw-------, .ssh/id_rsa.pub is -rw-r--r--

Questioner
Nicolas Raoul
Viewed
0
7,170 2019-11-14 22:45:38

Are you sure you cloned it using the ssh url?

The url for origin says url = https://Nicolas_Raoul@bitbucket.org/Nicolas_Raoul/therepo.git so if it is using https it will ask for password irrespective of your ssh keys.

So what you want to do is the following:

open your config file in your current repo ..

vim .git/config

and change the line with the url from

[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