0

There is this weird bug, where clients that have previously connected to the server via ssh, upon disconnecting and trying to reconnect at a later time, receive a "port 22 Connection refused" error message. I have to restart the client machine in order to be able to reconnect. Any client that has not previously connected to the ssh server can still connect at any time.

Any ideas on why this happens? service sshd status doesn't show any problems, and auth.log doesn't even register these attempts. The firewall is disabled as well.

A typical connection from a Windows 10:

OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2
debug3: Failed to open file:C:/Users/baric/.ssh/config error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2
debug2: resolve_canonicalize: hostname 192.168.1.101 is address
debug2: ssh_connect_direct
debug1: Connecting to 192.168.1.101 [192.168.1.101] port 22.
debug3: finish_connect - ERROR: async io completed with error: 10061, io:000002E37B8A09C0
debug1: connect to address 192.168.1.101 port 22: Connection refused
ssh: connect to host 192.168.1.101 port 22: Connection refused
3
  • That looks like a Windows problem: github.com/microsoft/WSL/issues/6882. Can you try the proposed solutions?
    – Freddy
    Feb 21, 2023 at 18:57
  • I don't appear to have the port reservations issues mentioned, and thus the proposed solutions didn't work.
    – Cheetaiean
    Feb 21, 2023 at 19:43
  • Update: this may be an issue with my OpenVPN which creates a different IP address to be run through tun0
    – Cheetaiean
    Feb 21, 2023 at 21:00

1 Answer 1

0

One possible explanation for this behavior could be that the SSH server is configured to limit the number of concurrent connections from the same IP address. When a client connects to the server for the first time, a new connection is established and registered in the server's connection table. However, when the client disconnects, the connection may not be immediately terminated on the server's side, but instead may remain in a timed-wait state for a short period of time. During this period, the server may still consider the client as connected and not allow new connections from the same IP address.

If the client tries to connect during this period, it will receive a Connection refused error message, as the server is still waiting for the previous connection to fully terminate.

To check if this is the case, you can try increasing the maximum number of concurrent connections allowed by the SSH server and see if the issue persists. You can also try adjusting the connection timeout values to see if that helps.

# find these two lines in /etc/ssh/sshd_config and try to reduce their values to see if it helps

ClientAliveInterval
ClientAliveCountMax

sudo systemctl reload ssh # (might be ssh on your server

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .