Search code examples
gitsshbitbucket

Git SSH public key denied


I'm using Bitbucket, and I've setup SSH on Git as instructed for Linux in Atlassian's documentation (Ubuntu 13.04)

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

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.

When I try ssh -T [email protected], only then does the terminal prompt me to enter my passphrase, and I get my account name as response.

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.

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

Am I missing something?


Solution

  • 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.