Git SSH public key denied

Deadly 提交于 2019-12-21 11:54:49

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/18470613/git-ssh-public-key-denied

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!