Git SSH 公钥被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18470613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git SSH public key denied
提问by Omkar Khair
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
我正在使用 Bitbucket,并且按照此处针对 Linux(Ubuntu 13.04)的说明在 git 上设置了 ssh 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
但是,当我尝试从我的 Bitbucket 帐户克隆一个任何项目时,我收到一个公钥被拒绝的错误
omk@home-pc:/var/www/git$ sudo git clone [email protected]: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.
我已将公钥添加到我的 bitbucket 帐户中。
When I try 'ssh -T [email protected]', only then does the terminal prompt me to enter my pass phrase and I get my account name as response.
当我尝试 'ssh -T [email protected]' 时,只有这样终端才会提示我输入密码,然后我得到我的帐户名作为响应。
omk@home-pc:/var/www/git$ ssh -T [email protected]
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?
在 $HOME 克隆工作正常。问题在于必须在 /var/www/git 上使用 sudo。有什么办法可以更改权限以避免使用 sudo?
回答by michas
Use ssh-add $keyfile
to add your private key to the agent.
使用ssh-add $keyfile
你的私钥添加到代理。
Then use ssh-add -L
to display the public key for that key. - Verify it matches the one added to your bitbucket account.
然后用于ssh-add -L
显示该密钥的公钥。- 验证它是否与添加到您的 bitbucket 帐户的匹配。
Now trying to ssh to bitbucket should result login via key, i.e. nopassword is needed.
现在尝试 ssh 到 bitbucket 应该导致通过密钥登录,即不需要密码。
Also git clone
over ssh should work now.
git clone
现在也可以通过 ssh 工作。
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.
使用sudo
可能不是一个好主意。它肯定会切断与您的代理的连接并更改 $HOME/.ssh,因此由 sudo 启动的 ssh 将无法使用您的密钥。您可以使用sudo -E
来保护您的环境。在这种情况下,密钥应该仍然有效。