Git SSH公钥被拒绝 [英] Git SSH public key denied

查看:849
本文介绍了Git SSH公钥被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Bitbucket,并且我已经在git上设置了ssh(按照Linux(Ubuntu 13.04)的指示)
https://confluence.atlassian.com/pages/viewpage.action?pageId=270827678



当我尝试克隆一个我的Bitbucket帐户的任何项目,但我得到一个公钥拒绝错误

  omk @ home-pc:/ var / www / git $ sudo git clone git@bitbucket.org:MyAccount / MyProject.git 
克隆到'MyProject'...
Permission denied(publickey)。
致命:无法从远程存储库读取。

请确保您拥有正确的访问权限
并存在存储库。

我已将公钥添加到我的bitbucket帐户中。



当我尝试'ssh -T git@bitbucket.org'时,终端只会提示我输入我的密码短语,并将我的帐户名称作为响应。

  omk @ home-pc:/ var / www / git $ ssh -T git@bitbucket.org 
以MyUsername身份登录。

您可以使用git或hg连接到Bitbucket。外壳访问被禁用。

我是否缺少某些东西?

更新:



克隆在$ HOME可以正常工作。问题是不得不在/ var / www / git中使用sudo。任何方式我更改权限,以避免使用sudo?

解决方案使用 ssh-add $ keyfile


$ b

然后用 ssh-add -L 来添加您的私钥给代理。显示该密钥的公钥。 - 验证它是否与添加到您的bitbucket帐户中的相匹配。



现在尝试使用ssh访问bitbucket应该会导致通过密钥登录,例如 no password is is



还有 git clone over ssh现在可以使用。



使用 sudo 可能不是个好主意。它肯定会切断与您的代理的连接并更改$ HOME / .ssh,因此由sudo启动的ssh将无法使用您的密钥。
您可以使用 sudo -E 来保存您的环境。在这种情况下,钥匙仍然可以工作。


I'm using Bitbucket, and I've setup ssh on git as instructed here for Linux (Ubuntu 13.04) https://confluence.atlassian.com/pages/viewpage.action?pageId=270827678

When I try to clone one any project from my Bitbucket account though, I get a public key denied error

omk@home-pc:/var/www/git$ sudo git clone git@bitbucket.org:MyAccount/MyProject.git
Cloning into 'MyProject'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I have added the public key to my bitbucket account.

When I try 'ssh -T git@bitbucket.org', only then does the terminal prompt me to enter my pass phrase and I get my account name as response.

omk@home-pc:/var/www/git$ ssh -T git@bitbucket.org
logged in as MyUsername.

You can use git or hg to connect to Bitbucket. Shell access is disabled.

Am I missing something?

UPDATE:

Cloning at $HOME works fine. The issue is with having to use sudo at /var/www/git. Any way I change the permissions to avoid using sudo?

解决方案

Use ssh-add $keyfile to add your private key to the agent.

Then use ssh-add -L to display the public key for that key. - Verify it matches the one added to your bitbucket account.

Now trying to ssh to bitbucket should result login via key, i.e. no password is needed.

Also git clone over ssh should work now.

Using sudo is probably no good idea. It will most certainly both cut the connection to your agent and change $HOME/.ssh, hence a ssh started by sudo will not be able to use your key. You can use sudo -E to preserve your environment. In this case the key should still work.

这篇关于Git SSH公钥被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆