Ssh: connect to host [public ip] port 22: Connection refused

centos7ssh

I have a CentOS 7 VM Instance on GCP, I have a cron job on my local infra that connects to GCP Instance every minute to check some parameters on GCP VM Instance.

Most of the time the ssh [public ip] command works, but some times I get this error "ssh: connect to host [public ip] port 22: Connection refused"

Is there max connection limit that I can increase.

Thanks

IJ

Best Answer

Indeed. Check sshd_config's man page man sshd_config

If not already, it might not be a bad idea to check your auth.log for some additional info as well.

[root@server ~]# vi /etc/ssh/sshd_config
# make the changes and restart the service
[root@server ~]# systemctl restart sshd

Some more info on the configuration variables:

MaxSessions Specifies the maximum number of open shell, login or subsystem (e.g. sftp) sessions permitted per network connection. Multiple sessions may be established by clients that support connection multiplexing. Setting MaxSessions to 1 will effectively disable session multiplexing, whereas setting it to 0 will prevent all shell, login and subsystem sessions while still permitting for- warding. The default is 10.

MaxStartups Specifies the maximum number of concurrent unauthenticated con- nections to the SSH daemon. Additional connections will be dropped until authentication succeeds or the LoginGraceTime expires for a connection. The default is 10:30:100. Alternatively, random early drop can be enabled by specifying the three colon separated values start:rate:full (e.g. "10:30:60"). sshd(8) will refuse connection attempts with a probability of rate/100 (30%) if there are currently start (10) unauthenticated connections. The probability increases linearly and all connec- tion attempts are refused if the number of unauthenticated con- nections reaches full (60).