Git SSH public key denied
Asked Answered
L

3

7

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?

Lipp answered 27/8, 2013 at 16:11 Comment(4)
Is it possible to clone into your home directory without using sudo?Caraviello
Nope. Gives me this - fatal: could not create work tree dir 'easydial'.: Permission deniedLipp
Did you try to clone to $HOME, or /var/www/git? (you probably have permission to write to the first, but not to the last.)Caraviello
Cloning at $HOME works. Any way I can set permissions to /var/www/git to not use sudo?Lipp
C
12

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.

Caraviello answered 27/8, 2013 at 16:27 Comment(8)
Still the same error. But I see 2 keys on ssh-add -L now. The same key basically. One ends with /home/omk/.ssh/id_rsa and the other with omk@home-pc.Lipp
Any way I could avoid using sudo. I am sensing that is the issue.Lipp
Just found. Using clone on $HOME works fine. Any way I can change the permissions for /var/www/Lipp
Either use chown on /var/www/git, or use sudo -E. - Depending on, what you are planning to do with the repository.Caraviello
Did a cd ; sudo cp .ssh/id_* /root/.ssh/ to move my keys to root. Worked! Thanks :)Lipp
When I run: ssh-add -L, it lists multiple keys. How which one should I be verifying with BitBucket??Dumpish
If your agent knows about multiple keys, you can use any of them. Maybe you should find out where the second key comes from. Probably your desktop environment added a key from ~/.ssh/.Caraviello
You saved my life, thank you! -E option made my day.Voracious
B
0

Add yourself to the group that has access to /var/www/git.

Bywaters answered 20/11, 2023 at 17:34 Comment(0)
N
-2

I had similar problem and I solved like that: First, I enabled passwd auth then added public key and then disables passwd auth again. I know this is not exactly your problem but I wanted to share my experience.

Normalie answered 30/6, 2022 at 9:16 Comment(2)
Chill :) Just wanted to tell my story.Normalie
Please see: How to write good answer?Hedgehog

© 2022 - 2024 — McMap. All rights reserved.