Skip to content

Instantly share code, notes, and snippets.

@Tamal
Last active May 9, 2025 19:59
Show Gist options
  • Save Tamal/1cc77f88ef3e900aeae65f0e5e504794 to your computer and use it in GitHub Desktop.
Save Tamal/1cc77f88ef3e900aeae65f0e5e504794 to your computer and use it in GitHub Desktop.
Solution for 'ssh: connect to host github.com port 22: Connection timed out' error
$ git clone git@github.com:xxxxx/xxxx.git my-awesome-proj
Cloning into 'my-awesome-proj'...
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.
$ # This should also timeout
$ ssh -T git@github.com
ssh: connect to host github.com port 22: Connection timed out
$ # but this might work
$ ssh -T -p 443 git@ssh.github.com
Hi xxxx! You've successfully authenticated, but GitHub does not provide shell access.
$ # Override SSH settings
$ vim ~/.ssh/config
```
# Add section below to it
Host github.com
Hostname ssh.github.com
Port 443
```
$ ssh -T git@github.com
Hi xxxxx! You've successfully authenticated, but GitHub does not
provide shell access.
$ git clone git@github.com:xxxxxx/xxxxx.git my-awesome-proj
Cloning into 'my-awesome-proj'...
remote: Enumerating objects: 15, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 15 (delta 0), reused 15 (delta 0), pack-reused 0
Receiving objects: 100% (15/15), 22.90 KiB | 4.58 MiB/s, done.
@REBOOTERS
Copy link

great job ,thanks .

@wgzhang
Copy link

wgzhang commented Jul 10, 2023

Thanks~ It worked for me

@r41ng3l
Copy link

r41ng3l commented Jul 22, 2023

For the people that have tried all the above solutions and none of them have worked: It may be a DNS resolution problem. I'm working from a WSL instance in Windows 11 Pro. Here are few things you can try to check if it is a DNS resolution issue:

dig ssh.github.com
dig google.com
ping google.com

If none of the above commands works, e.g. for the dig google.com this would be a good output:

; <<>> DiG 9.18.12-0ubuntu0.22.04.1-Ubuntu <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25537
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;google.com.                    IN      A

;; ANSWER SECTION:
google.com.             300     IN      A       216.58.208.110

;; Query time: 40 msec
;; SERVER: 8.8.8.8#53(8.8.8.8) (UDP)
;; WHEN: Sat Jul 22 11:52:38 CEST 2023
;; MSG SIZE  rcvd: 55

And this would be a bad output:

;; communications error to 172.24.128.1#53: timed out

The same applies to the dig ssh.github.com command.

If you are getting the timed out outputs of the dig commands, next step is to check the /etc/resolv.conf file

Mine was pointing out to an unreachable nameserver and thus name resolution wasn't being possible.

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.24.128.1

I added Google's nameserver (you can add any nameserver of your preference)

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
# nameserver 172.24.128.1
nameserver 8.8.8.8
nameserver 8.8.4.4

Save the file (remember to edit it as sudo) and try the dig command again. If you get the good output, the issue was the unreachable nameserver. If you still get a timed out output in the dig command there might be a problem with the port 53 in your network. I cannot provide further information as my issue was the nameserver.

After solving the nameserver issue the command ssh -T git@ssh.github.com and any domain related command should work beautifully now.

@tcpdump-examples
Copy link

I found this article is very useful. I got more ideas about how to fix this issue. https://www.howtouselinux.com/post/ssh-connect-to-host-port-22-connection-timed-out

@junglejf
Copy link

I have been trying to fix still Im getting stuck

hope@hope-HP-ProBook-450-G2:~$ ssh -T git@github.com kex_exchange_identification: Connection closed by remote host Connection closed by 185.199.108.153 port 443

please help me

I'm getting same issue :(
ssh -T -p 443 git@ssh.github.com
kex_exchange_identification: Connection closed by remote host
Connection closed by 20.201.28.152 port 443

@tcpdump-examples
Copy link

tcpdump-examples commented Jul 28, 2023

@junglejf I think you can use curl -v telnet://ssh.github.com:443 to test your network connectivity to github. if the connection is not connected, you need to check this on the network side. if it shows like below, it means the network connection is good. You can check your ssh key file.

 % curl -v telnet://ssh.github.com:443
*   Trying 140.82.113.35:443...
* Connected to ssh.github.com (140.82.113.35) port 443 (#0)
ssh -T -p 443 -i /path/your/private/key git@ssh.github.com

@GabrieleCalarota
Copy link

It worked thank you!

@nguaman
Copy link

nguaman commented Aug 2, 2023

<3

@Johnny09887
Copy link

after putting the lines that you tell me how to close the file and save it

@pyae-gyi
Copy link

pyae-gyi commented Aug 5, 2023

after putting the lines that you tell me how to close the file and save it

after putting the lines that you tell me how to close the file and save it

I found it is a lot more easier to save if you used microsoft visual code to open ~/.ssh/config. So I opened using code ~/.ssh/config. Then I overwrote this inside config file. Finally it worked.

@pengshancai
Copy link

works for me, thanks!

@tmagrit
Copy link

tmagrit commented Aug 18, 2023

Worked perfectly to me on Debian 10. Thank you so much!

@thisIsShikhar
Copy link

it worked! thank you!

@YuriTimafejn
Copy link

Thank you.

@xiaoxinmiao
Copy link

Thanks~ It worked for me

Host github.com
Hostname ssh.github.com
User xiaoxinmiao
Port 443
IdentityFile /c/Users/Administrator/.ssh/github

@xnh66
Copy link

xnh66 commented Aug 28, 2023

Thanks!

@litone01
Copy link

Thank you so much, you saved my day!

@NaN-MS
Copy link

NaN-MS commented Sep 12, 2023

Thank you

@sernamalala
Copy link

Thanks alot! it worked.

@noma4i
Copy link

noma4i commented Sep 26, 2023

Thanks god I was able to google this gist

@odellus
Copy link

odellus commented Oct 1, 2023

THANK YOU

@th-sakib
Copy link

th-sakib commented Oct 3, 2023

THANK YOU SO MUCH IT WORKED ..... AFTER 3HOUR OF HUSSLE ..... THANK YOU REALLY

@cbatista8a
Copy link

it's work for me

@Dinis-Khakimov
Copy link

if you don't get the expected result, then perform another option via the command line:

git config http.sslVerify false

@Ghostvulture
Copy link

Thank you so much!!!! I've been struggling for days for this

@buihien224
Copy link

Thanks u so much bro

@LizaDakhova
Copy link

Thank you! It works!

@Miguelmalaj
Copy link

this works to me, thanks a million

@briantci
Copy link

briantci commented Jan 6, 2024

thank you very much, works for me as well.

@pedrinho81
Copy link

Nice!! it works perfectly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment