Hub: Permission denied (publickey)

Created on 5 Jan 2015  路  11Comments  路  Source: github/hub

I just installed hub and am having trouble pushing to github.

I tried to create a new repo on github and got an error. I was able to fix it with the workaround that @mislav suggested in #706. When I check on GitHub using my browser, I can see that the repo exists. However, when I try to push to the newly created repo, I get an ssh error.

Pushing to [email protected]:manleyjster/trilobite.git
Failed to add the RSA host key for IP address '192.30.252.129' to the list of known hosts (/home/justin/.ssh/known_hosts).
Permission denied (publickey).
fatal: Could not read from remote repository.

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

Any idea what the problem is? I have 2fa enabled, but pushing to GitHub was working fine immediately before I installed hub.

Most helpful comment

@manleyjster OK, makes sense. You definitely want to set git config --global hub.protocol https.

All 11 comments

Looking at the first line - wondering if this might have something to do with #690?

In ~/.config/hub, I have the protocol set to https. It looks like hub is using git despite this - perhaps the source of my problem?

I have met the same error Permission denied (publickey) before. It's usually caused by public key not attaching to your GitHub account. But your comment "pushing to GitHub was working fine immediately before I installed hub" gets me to think it might be something else. Could you run ssh -T [email protected] to make sure it's not a certificate issue? You should see something like this if your certificate is associated properly:

$ ssh -T [email protected]
Hi jingweno! You've successfully authenticated, but GitHub does not provide shell access.

You mentioned you create a repo on GitHub. Did you create it using hub create? Also it'd be useful to know the version of hub you're using: hub version.

Fixed.

The issue was that I had created the issue using hub create before I set the protocol to https in ~/.config/hub, and so hub create set the remote url to use git rather than https. I reset the remote using git remote set-url and that solved the problem.

Thanks for the quick response, @jingweno!

I'm not sure if I understand what caused your original issue, but I'm glad you solved it. Note that hub doesn't provide any extra functionality for git push command with regards to authentication. So, the error that you were getting seems like it was caused by git misconfiguration rather than hub misconfiguration.

Here's what I think might have happened -

I normally push to github using https, not ssh, and I don't think I've configured git on my computer to use the correct private key to connect to github.

When I created my new repo using hub create, since I hadn't explicitly configured hub via ~/.config/hub,hub createset the remote to[email protected]:manleyjster....` - i.e. it set the git repo to connect to github via ssh. Once I realized this and manually reset the remotes to https, pushing worked just fine.

Not a bug, just a misunderstanding on my part!

@manleyjster OK, makes sense. You definitely want to set git config --global hub.protocol https.

How do I do this

@manleyjster OK, makes sense. You definitely want to set git config --global hub.protocol https.
Works, thanks.

@manleyjster OK, makes sense. You definitely want to set git config --global hub.protocol https.

This worked for me. No more problems.

This is the perfect solution
https://stackoverflow.com/questions/26953071/github-authentication-failed-github-does-not-provide-shell-access
try->
git remote set-url origin [email protected]:"path of the repo"
example->
git remote set-url origin [email protected]:lut/EvolutionApp.git

OK, makes sense. You definitely want to set git config --global hub.protocol https.

Why is this not the default? I couldn't clone anything with hub until I found this page.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

le0nik picture le0nik  路  4Comments

wwwdata picture wwwdata  路  3Comments

nicksergeant picture nicksergeant  路  3Comments

jfritzbarnes picture jfritzbarnes  路  3Comments

dsifford picture dsifford  路  4Comments