Skip to content

Git SSH 登录超时

Git 命令报错:ssh connect to host github.com port 22 Connection timed out

1
2
3
ssh: connect to host github.com port 22: Connection timed out
Please make sure you have the correct access rights
and the repository exists.

首先输入以下命令检查SSH是否能够连接成功(ssh后面有空格),发现报错,提示端口连接超时

$ ssh -T git@github.com
ssh: connect to host github.com port 22: Connection timed out

解决方案

  1. 找到 .ssh 目录,此前配置 SSH 时已生成该目录;
  2. .ssh 目录中新建文件 config
  3. 打开 config 文件,输入以下内容,保存再测试
1
2
3
4
5
6
Host github.com
    User user-mail@example.com
    HostName ssh.github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa
    Port 443 

再次执行,会出现以下提示,输入 yes 回车即可

1
2
3
4
5
6
7
$ ssh -T git@github.com
The authenticity of host '[ssh.github.com]:443 ([20.205.243.160]:443)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[ssh.github.com]:443' (ED25519) to the list of known hosts.
Hi yuikuen! You've successfully authenticated, but GitHub does not provide shell access.