As the title, a sudden error is reported during git use
ssh:connect to host github.com port 22: Connection timed out
After consulting various materials, it is known that the reason may be that port 22 of the ssh connection method is blocked due to the firewall of the computer or other network reasons .
Solution
One: Abandon the ssh connection method and use http connection.
git config --local -e
将配置文件的url = [email protected]:username/repo.git一行改为:url = https://github.com/username/repo.git
Method 2 : If port 22 does not work, then change to another port
Go to the .ssh folder
Create a config file
Copy the following content into
Host github.com
User git
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443
Host gitlab.com
Hostname altssh.gitlab.com
User git
Port 443
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
save and exit
Check for success
ssh -T [email protected]
Here you need to operate according to its prompts, there is a place to enter yes
You're done now