ssh – Periodically it is impossible to connect from external

Question:

To connect to the server remotely, I use ssh user@host , and I don't have to.

Sometimes it connects normally, sometimes crashes

port 22: Connection timed out

The standard port did not change. In general, I did not change anything, all the settings are default.

The same story with mounting sshfs , every other time.

Even more often it does not connect.

Where to look for the reason? Well, I would not be able to connect at all, but sometimes everything is fine.

In LAN everything works like clockwork.

Answer:

if connections with other ports are normal, then network failures along the path of packets and temporary server overload can be excluded.


perhaps, somewhere along the path of the packets, filters are triggered, limiting the number of new connections per unit of time to a given port.


further I proceed from the assumption that any of the distributions of the gnu / linux operating system is installed on the server.

to determine if this is happening on your server, or even before it, you should make sure that connection attempts are recorded in the logs ( /var/log/auth.log , /var/log/audit/audit.log , etc.) in those moments when you get the connection timed out error.

It is also worth inspecting the netfilter rules on your server for restrictive rules :

$ sudo iptables-save | grep limit

update about another port :

and, of course, it makes sense to try connecting to a different port: add the line port номер_порта on the server to /etc/ssh/sshd_config (in addition to the already existing port 22 ) and connect using this port ( sshd will need to be restarted):

$ ssh -p номер_порта пользователь@машина

номер_порта makes sense to choose номер_порта from the range "greater than 1024" (the maximum number is 2 16 = 65536).

and in order not to specify the port every time, add a couple of lines to ~/.ssh/config :

host машина
port номер_порта
Scroll to Top