60

When I follow point 5 (Test everything out) in the github guide, the ssh command also hangs forever. According to the guide, I should be presented with a message that "Github does not provide shell access". Below is my output from ssh -vT git@github.com

debug1: Authentication succeeded (publickey).
Authenticated to github.com ([207.97.227.239]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LC_MESSAGES = en_US.UTF-8
debug1: Sending env LC_COLLATE = en_US.UTF-8
debug1: Sending env LANG = da_DK.UTF-8
debug1: Sending env LC_CTYPE = en_US.UTF-8
rvange
  • 2,432
  • 2
  • 20
  • 23
  • 1
    Is there potentially any sort of filtering/blocking between you and GitHub? – Cascabel Jan 05 '12 at 23:08
  • 2
    Out of curiosity, are you able to connect to other SSH servers (using keys) without issues? – Marvin Pinto Jan 05 '12 at 23:10
  • I also thought it may be filtering but notice the auth succeeds, if it were a firewall it would timeout eventually before that. – Samus_ Jan 06 '12 at 00:19
  • I tried every workaround mentioned here & even double checked using the `ssh -T git@github.com` command which appears to be working fine. Yet the connection times out over port 22. Answers from this thread - https://stackoverflow.com/q/15589682/8604951 might help someone connect to GitHub properly while this thread -- https://stackoverflow.com/q/25927914/8604951 should help set up access rights to the remote in GitHub properly. But in the end, cloning over HTTPS worked for me. It's not worth the pain IMHO to set up a SSH connection unless TOTALLY necessary. – Jarmos Jun 07 '20 at 11:47

17 Answers17

58

GitHub offers a few different ways to connect to the remote repo. I am behind an onerous firewall. All methods also hang except using http (not https).

For example, the JavaHamcrest project offers (anonymously):

You may also try:

Finally, prefix your UNIX command with GIT_TRACE=1 and GIT_CURL_VERBOSE=1, and use Git option --verbose for maximum debug output.

Example: env GIT_TRACE=1 GIT_CURL_VERBOSE=1 git clone --verbose http://github.com/hamcrest/JavaHamcrest.git

kevinarpe
  • 20,319
  • 26
  • 127
  • 154
  • 4
    It appears `http` (not `https`) links doesn't work for `github` anymore. I.e. your example command doesn't work as it's using `http` scheme. – x-yuri Jul 30 '14 at 12:19
  • 1
    also check that you github account has ssh keys - https://inchoo.net/dev-talk/how-to-generate-ssh-keys-for-git-authorization/ – Mauricio Gracia Gutierrez Jun 14 '21 at 22:19
51

In my case port 22 was being blocked by a firewall, cloning via https may not work if you have 2-factor authentication enabled. Instead edit your .ssh config to use another port. In your terminal:

nano ~/.ssh/config

then add this:

Host github.com
  Hostname ssh.github.com
  Port 443
Hom Bahrani
  • 3,022
  • 27
  • 25
  • 3
    Just save me several minutes of digging around to find a solution. Thx!!! – Fedreg Feb 03 '20 at 21:03
  • Worked for me as well. All my ssh requests were hanging forever. Creating a ~/.ssh/config and adding some config there fixed my issue. Here's some [additional resource](https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port) from GitHub – lucianokrebs Jun 12 '22 at 20:49
  • This worked. I did add an exception to ssh.exe firewall rules but no thanks to managed firewall it does not function like I wanted to. Updating a config file is an extra step. For windows users: default location for adding such config file, with name "config" C:\Users\\.ssh\config where no file type is set – Erkka Mutanen Jun 13 '22 at 09:01
30

Try using HTTPS instead of SSH. Port 22 might be blocked by a firewall.

E.g. instead of:

git clone git@bitbucket.org:repo-owner/my-project.git

Connect via HTTPS:

git clone https://username@bitbucket.org/repo-owner/my-project.git
chribsen
  • 6,232
  • 4
  • 26
  • 24
22

I think I found the error. The WiMAX router I am using, messes SSH up. After trying another internet connection, it went smooth. The WiMAX router is branded "Alvarion", and according to a Danish Google Group the NAT implementation is broken in the router: http://groups.google.com/group/openspaceaarhus/browse_thread/thread/e99d96122a0522b7.

I have contacted the internet supplier to look into this. If they prove it has nothing to do with their router I will post it here.

Thank you all for your comments, which made me realise it maybe was an infrastructure problem.

rvange
  • 2,432
  • 2
  • 20
  • 23
4

Make sure that you have ssh installed.

Ubuntu: sudo apt-get install ssh

CraigDavid
  • 1,046
  • 1
  • 12
  • 26
2

I had the same issue on Xubuntu. Doing ssh -Tv git@github.com hangs forever. Disabling the firewall with sudo ufw disable solved the problem.

Christian Rodemeyer
  • 2,001
  • 1
  • 19
  • 22
2

Was having the same issue on Windows / msys2. Seems to be something with the router. I pinged github.com and then cloned using my username

git clone https://cchamberlain@github.com/cchamberlain/<repo>

and it worked. Not sure if its a one-off yet.

cchamberlain
  • 17,444
  • 7
  • 59
  • 72
1

In my case I found that my Anti-Virus was blocking access to Github. The popup appeared behind all my windows which I did not realize earlier. The moment I allowed access to GitHub "ssh -vT git@github.com" command worked. I was also able to clone a repository and push my code from local to Github.

Arif Shaikh
  • 79
  • 3
  • 10
1

If you have a different default SSH port in /etc/ssh/sshd_config, git clone won't work out of the box with a git@... url.

This solution above to the rescue.

Dhruv Batheja
  • 2,140
  • 1
  • 18
  • 16
0

Things to check when git clone and git push hang forever no error message

Mauricio Gracia Gutierrez
  • 10,288
  • 6
  • 68
  • 99
0

In my case was IPV6 blocking cloning, I disable ipv6 on ssh and works

Pablo Díaz
  • 330
  • 4
  • 14
0

Mine dumb case was that, I changed default SSH port in /etc/ssh/ssh_config instead of /etc/ssh/sshd_config

М.Б.
  • 1,308
  • 17
  • 20
0

Cloning it again solved the issue for me. Try again.

Leutecia
  • 95
  • 1
  • 4
  • 9
0

In my case an authentication/authorization pop-up window presented but somehow ended up being hidden behind other windows so I didn't see it. I minimized other windows to find it, logged in, and git clone continued normally.

gonzobrains
  • 7,856
  • 14
  • 81
  • 132
0

In my case, the MacOS keychain contains credentials, initially given from VS Code for github.com for the VS Code sync feature. I dont know, what I've changed in the meantime, maybe switched to 2FA, but with this credentials I was unable to login to github.com from the command line, neither via ssh nor https. After I've deleted the github.com entry in MacOS keychain, it works.

Dominik
  • 1,332
  • 1
  • 15
  • 28
-1

I was just struggling with that (after updating to using API Token instead of password, changes on github since July'21)

What helped me was to use http instead of https in git clone.

Simple as that.

radekbaranowski
  • 366
  • 4
  • 5
-1

in my case my /etc/resolv.conf was messed up, i noticed pc would fail to even ping google.com. Fixed that that and life was grand.

rrosa
  • 368
  • 4
  • 9