Connection timed out ssh linux

ssh: connect to host github.com port 22: Connection timed out

I am under a proxy and I am pushing in to git successfully for quite a while.
Now I am not able to push into git all of a sudden.
I have set the RSA key and the proxy and double checked them, with no avail and git is throwing me the error shown in the title of the page.

Create a hotspot on your mobile device, connect via your mobile device, then git push . Worked for me.

The same problem happened to me in the UK with Virgin Media. I tried to push/pull to GitHub via ssh at home and no luck but at work was fine. So I realised that I got problems with my ISP. The simple fix for me was to use Cloudflare DNS 1.1.1.1 instead of a default one that’s why @zundi succeed through a mobile hotspot.

31 Answers 31

For my case none of the suggested solutions worked so I tried to fix it myself and I got it resolved.

For me I am getting this error on my AWS EC2 UBUNTU instance, what I did to resolve it was to edit the ssh config (or add it if it does not exist).

And I added the following

Host github.com Hostname ssh.github.com Port 443 

Then, run the command ssh -T git@github.com to confirm if the issue is fixed.

Sometimes, firewalls refuse to allow SSH connections entirely. If using HTTPS cloning with credential caching is not an option, you can attempt to clone using an SSH connection made over the HTTPS port. Most firewall rules should allow this, but proxy servers may interfere

Hopefully this helps anyone else who’s having the same issue I did.

This solution worked fine for me, although it didn’t solve the issue for GitLab. In that case, please consider that GitLab.com runs a second SSH server that listens on the commonly used port 443, which is unlikely to be firewalled. All you have to do is edit your ~/.ssh/config and change the way you connect to GitLab.com. In that case, see this article: about.gitlab.com/2016/02/18/…

Hi, i had a same problem, my router is from NET and him block the 22 port. That config solved my problem definitely

After hours of finding anwers. you’re CHAMP, anyway why do we need to change github.com to ssh.github.com? I still don’t get it

The reason could be the firewall modification as you are under a network.(In which case they may deliberately block some ports)
To double check if this is the reason . do

this should timeout. If that’s the case use http protocol instead of ssh this way
just change your url in the config file to http.
Here is how :-

 url = git@github.com:username/repo.git 
url = https://github.com/username/repo.git 

using https instead for ssh is not the right solution. There must a way to set proxy in git config and in ssh settings to solve this.

inside the .ssh folder Create «config» file

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 

Basic URL Rewriting

Git provides a way to rewrite URLs using git config. Simply issue the following command:

git config --global url."https://".insteadOf git:// 

Now, as if by magic, all git commands will perform a substitution of git:// to https://

Читайте также:  Установка драйвера устройства линукс

Thanks! Ours was during the Jenkins build so I couldn’t manually edit the git file (I don’t have the git credentials for the jenkins account) — so this was very useful.

Concerning github, the command should be: git config —global url.»https://github.com/».insteadOf git@github.com: . Notice the differences: @ becomes // and : becomes / .

I faced the same problem and couldn’t find a working solution. I faced this problem while setting up a local server and the git couldn’t connect through my proxy network but my workstation could. This was the output when I ran the command ssh -vT git@github.com

ubuntu@server:~$ ssh -vT git@github.com OpenSSH_7.2p2 Ubuntu-4ubuntu2.8, OpenSSL 1.0.2g 1 Mar 2016 debug1: Reading configuration data /home/ubuntu/.ssh/config debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: Applying options for * debug1: Connecting to github.com [13.234.176.102] port 22. 

So I tried using an SSH connection made over the HTTPS port by editing the config file ~/.ssh/config but to no avail.

Host github.com Hostname ssh.github.com Port 443 

Finally, I found this article which solved and exposed the real problem.

# github.com Host github.com Hostname ssh.github.com ProxyCommand nc -X connect -x : %h %p Port 443 ServerAliveInterval 20 User git 

This is my config file and now git works perfectly well through ssh!

Источник

6 ways to troubleshoot ssh: connect to host port 22: Connection timed out

A connection timeout means that the client attempted to establish a network socket to the SSH server, but the server failed to respond within the timeout period.

ssh: connect to host 203.0.113.0 port 22: Connection timed out

In PuTTY, you might see an error window with text like this:

Network error: Connection timed out

In this article, we will dive into this issue and see how to troubleshoot this error:

Check SSH command syntax

The syntax for the SSH command is as follows:

ssh [options] [user@]hostname [command]

Here is a brief explanation of each part of the syntax:

  • ssh – This is the command to initiate the SSH connection.
  • [options] – This is an optional parameter that allows you to specify additional options to configure the SSH connection. For example, you can use the -p option to specify a non-standard SSH port.
  • [user@]hostname – This is the remote host that you want to connect to. You can optionally specify a username to use for the SSH connection. If you omit the username, the default username for your current session will be used.
  • [command] – This is an optional parameter that allows you to specify a command to run on the remote host after the SSH connection is established. If you omit this parameter, you will be dropped into an interactive shell on the remote host.

Here is an example of how to use the SSH command to connect to a remote host:

This will initiate an SSH connection to the host example.com using the username username.

If you have already set up SSH keys, you will be logged in without being prompted for a password. If not, you will be prompted to enter your password.

Enable verbose output in SSH command

The ssh -vvv command is used to establish an SSH connection to a remote server with verbose output enabled. The -v flag stands for “verbose,” and it can be used up to three times in a row (i.e., -v, -vv, -vvv) to increase the level of detail in the output. Here’s what each level of verbosity provides:

  • -v: Verbose mode, displays debug messages about the authentication process and other connection details.
  • -vv: Provides additional debug information and more details about the connection process.
  • -vvv: Provides the most detailed output, including debugging information about the SSH handshake and messages exchanged during the connection process.
Читайте также:  Linux узнать состав группы

Using the -vvv flag is helpful when troubleshooting SSH connection issues, as it provides a wealth of information that can help pinpoint the problem.

However, keep in mind that the output can be quite verbose and overwhelming, so it’s usually best to start with the -v or -vv flags and work your way up to -vvv if needed.

Confirm that the server is correct

To confirm that the server’s IP address is correct, you can use ping command and follow these steps:

Identify the server that you want to connect to. This could be a domain name, a hostname, or an IP address.

Open a command prompt or terminal window on your local machine.

Type the following command, replacing server_address with the domain name, hostname, or IP address of the server:

This will send a small packet of data to the server and wait for a response. If the hostname is resolvable, you should see a series of responses.

Look at the IP address displayed in the ping results to confirm that it matches the expected IP address for the server.

If the hostname is not resolvable, you will see a message indicating that the hostname could not be resolved.

In this case, you may need to check your DNS settings or use a different hostname or IP address to connect to the server.

Check that the network allows SSH traffic over the port being used.

Some public networks may block port 22 or custom SSH ports.To check if the network allows SSH traffic over the port being used, you can follow these steps:

Identify the port number being used for SSH on the server. The default port number for SSH is 22, but some servers may use a custom port number.

Open a command prompt or terminal window on your local machine.

Type the following command, replacing port_number with the port number being used for SSH:

telnet server_address port_number

This will attempt to establish a connection to the server using the Telnet protocol on the specified port. If the network allows SSH traffic on this port, you should see a message indicating that the connection was successful.

If the network does not allow SSH traffic on this port, you will see a message indicating that the connection could not be established.

If the network is blocking SSH traffic on the port being used, you may need to use a different port number for SSH, or configure the network to allow SSH traffic on the current port.

For example, to check if the SSH port (port 22) is open on a remote server with the IP address 192.168.1.1, you can use the following command:

If the port is open, you will see something like this:

Trying 192.168.1.1.
Connected to 192.168.1.1.
Escape character is ‘^]’.
Press CTRL + ] and then type quit to exit.

Читайте также:  Linux copy and paste in terminal

If the port is not open, you will see an error message like this:

Trying 192.168.1.1.
telnet: Unable to connect to remote host: Connection refused

Verify the firewall rules on both the client and server

Identify the firewall software that is running on both the client and server machines. Common firewall software includes iptables on Linux and Windows Firewall on Windows.

Check the firewall rules on both the client and server to ensure that they are not set to DROP traffic by default. If the default policy is set to DROP, incoming traffic will be blocked by default and will need to be explicitly allowed.

Check that the SSH port is permitted for incoming connections. By default, SSH uses port 22, but some servers may use a custom port number.

On Linux machines with iptables, you can use the following command to list the current firewall rules:

On Windows machines, you can use the Windows Firewall with Advanced Security console to view and manage firewall rules.

Look for a rule that allows incoming traffic on the SSH port. If such a rule exists, the SSH port is permitted for incoming connections. If there is no such rule, you may need to create a new rule to allow incoming traffic on the SSH port.

On Linux machines with iptables, you can use the following command to add a new rule to allow incoming traffic on the SSH port:

sudo iptables -A INPUT -p tcp —dport ssh -j ACCEPT

This command adds a new rule to the INPUT chain of the iptables firewall to accept incoming traffic on the SSH port. The -p tcp option specifies that the rule applies to TCP traffic, and the –dport ssh option specifies the destination port as the SSH port (port 22 by default). Finally, the -j ACCEPT option tells iptables to accept incoming traffic that matches the specified rule.

Note that this command only adds the new rule temporarily and will be lost when the system is rebooted. To make the rule persistent, you will need to save the iptables configuration. This can be done using the following command:

sudo iptables-save > /etc/sysconfig/iptables

This command saves the current iptables configuration to the /etc/sysconfig/iptables file, which is read at boot time to restore the firewall rules.

Increase the timeout value for the SSH command

To increase the timeout value for the SSH command, you can use the -o option with the ServerAliveInterval parameter. This option sets the time interval (in seconds) between sending packets to the server to request a response and keep the connection alive.

For example, to set the timeout value to 120 seconds (2 minutes), you can use the following command:

ssh -o ServerAliveInterval=120 username@hostname

This will send a packet every 120 seconds to the server to keep the connection alive. If the server does not respond to any of these packets within the specified interval, the connection will be closed and the SSH command will time out.

David is a Cloud & DevOps Enthusiast. He has years of experience as a Linux engineer. He had working experience in AMD, EMC. He likes Linux, Python, bash, and more. He is a technical blogger and a Software Engineer. He enjoys sharing his learning and contributing to open-source.

howtouselinux.com is dedicated to providing comprehensive information on using Linux.

We hope you find our site helpful and informative.

Источник

Оцените статью
Adblock
detector