15

I get fatal:Authenication Failure when I try to push code to my repo. I've added the public key on my github account as well. When I do : ssh -i git@github.com
I get Hi amangupta052! You've successfully authenticated, but GitHub does not provide shell access.

Can anyone help? Thanks

Aman Gupta
  • 557
  • 1
  • 8
  • 23

1 Answers1

40

That depends on the remote url you have used.

If git remote -v returns:

https://github.com/username/reponame

Then your ssh setup won't matter. But this would work:

ssh://git@github.com:username/reponame

Another cause is linked to your private key: if it is pass-phrase protected, with a special character in it, that usually don't work well.
See here for other ssh causes of failure.


To replace your remote named origin, use git remote commands:

git remote set-url origin ssh://git@github.com:username/reponame

(as explained in the GitHub help page about changing the rmeote url)

If you see::

ssh: Could not resolve hostname github.com:amangupta052: 
     Name or service not known 
fatal: The remote end hung up unexpectedly

Try the non-scp ssh syntax:

git remote set-url origin ssh://git@github.com/username/reponame

(note the '/' instead of the ':' after github.com)

Maybe this would have worked, as commented in this blog post:

git remote set-url origin git@github.com:username/reponame

(scp-like syntax, but without the ssh:// prefix)

As I mention here, an scp syntax usually means an ~/.ssh/config file to work properly.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Ok so my origin is https one, how can I get the ssh origin? I'm sorry I'm really new to git. – Aman Gupta Jul 10 '13 at 20:34
  • @AmanGupta no problem, I have edited my answer. Replace '`username`' and '`reponame`' by the appropriate values. – VonC Jul 10 '13 at 20:35
  • Ok, I set the new origin. I get ssh on doing git remote -v. But now, I get `ssh: Could not resolve hostname github.com:amangupta052: Name or service not known fatal: The remote end hung up unexpectedly` on doing `git push` – Aman Gupta Jul 10 '13 at 20:39
  • @AmanGupta is that the output of the `git remote set-url` command, or of the `git push` you could do just after? – VonC Jul 10 '13 at 20:41
  • @AmanGupta but you accepted the answer, does that mean the `git push` finally worked? – VonC Jul 10 '13 at 20:43
  • haha, no I thought you'd have the answer in your next comment! – Aman Gupta Jul 10 '13 at 20:44
  • @AmanGupta I have edited the answer to address your error message on `git push`. – VonC Jul 10 '13 at 20:45
  • I enabled two factor authentication, and suddenly started to receive this error. Apparently, https does not work with two factor auth, so if you enable that it is a good idea to switch to the ssh based login. – joscarsson Feb 01 '14 at 23:26
  • @joscarsson 2FA (2 Form Authentication) should work with https without any issue: you need to gneerate a PAT (Personal Access Token). See http://stackoverflow.com/questions/13800289/configure-git-clients-like-github-for-windows-to-not-ask-for-authentication/18607931#18607931. – VonC Feb 02 '14 at 08:45