2011-12-22 143 views
111

我上传了我的~/.ssh/id_rsa.pubBitbucket's SSH keys作为explained,但Git仍然要求我在每次操作(例如git pull)时都要求我输入密码。我错过了什么?Git Bitbucket:即使上传我的公用SSH密钥,也总是要求输入密码

这是一个私人仓库(另一人的私人仓库的叉),我克隆它是这样的:

git clone [email protected]: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://[email protected]/Nicolas_Raoul/therepo.git 
[branch "master"] 
     remote = origin 
     merge = refs/heads/master 

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

回答

177

你确定你使用ssh链接克隆呢?

原始URL说url = https://[email protected]/Nicolas_Raoul/therepo.git所以如果它使用https,它会要求输入密码,而不管你的ssh密钥。

+40

你是对的,谢谢!我最有可能用错误的URL克隆。我用'[email protected]:Nicolas_Raoul/therepo.git'替换了'.git/config'中的URL,现在它起作用了! – 2011-12-22 07:55:36

+7

和更改远程使用git http://stackoverflow.com/questions/2432764/how-to-change-a-remote-repository-uri-using-git – 2012-09-12 03:41:39

+3

这是bitbucket谁建议我https网址创建存储库时!怎么来的! – 2013-08-25 16:03:59

9

在HTTP请求的情况下,也和另一种可能是粘贴凭证(带密码)直接进入网址:

http://username:[email protected]/... 

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

+4

但不安全。如果密码有一些像'$%'这样的字母, – Gank 2016-05-13 15:45:57

15

至于解释here,如果你有SSH链接克隆,你需要输入用户名/密码,每次推/拉时间。检查上述answer通过@manojlds

但是,如果你想与HTTPS克隆,并希望避免输入用户名/密码,每一次,你可以凭据存储到缓存以下命令:

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

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

+1

就不能工作了,就像为我节省了很多时间!谢谢! – 2018-01-01 01:33:32

4
+0

我认为'步骤1'是'Windows','步骤2'是'Linux',但是你忘记了正确提到它。 – 2016-08-09 18:15:27

+0

我在Windows系统上运行了这3个步骤,它工作正常。 – webdev5 2016-08-09 19:30:07

+2

在这种情况下,我想补充一点,在Linux操作系统上,我们只需要step2和step3来获得相同的效果:) – 2016-08-10 00:08:12

7

它已在上面回答。我将总结上面检查的步骤。

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

所以要更改远程URL运行git remote set-url origin {ssh remote url address starts with mostly [email protected]:}

现在运行git remote -v来验证已更改的远程URL。

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

1

下面假设通过的iTerm /终端的命令行访问到位桶。

对于MacOS Sierra 10.12.5,我的系统表现出一个同样的问题 - 在每个到bitbucket的连接上请求我的SSH密码。

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

你很好可能需要调整您的解决方案,但如果添加到您的〜/ .ssh/config文件下面的工作:

Host * 
    UseKeychain yes 

有关SSH CONFIGS更多信息,请看看手册页ssh_config中:

% man ssh_config 

一件事:有上超级here根据自己的需要和设置,讨论这个问题和各种解决方案的好写了。