I am using a code deployment service that connects to my server and execute commands. It connects, run some commands, disconnects and repeat.

I am always getting connection refused on the 8th connection within the same deployment.

From the service itself, all I can see is ssh: connect to host xxx port 22: Connection refused

I only see the connecting and disconnecting in /var/log/auth.log -- No connection refused errors.

For reference this is what I see in auth.log:

Accepted publickey for envoyer from port 50177 ssh2: RSA
Received disconnect from port 50177:11: disconnected by user
Disconnected from port 50177
pam_unix(sshd:session): session closed for user envoyer
Removed session 5996.
... repeated

How can I find out why it's refusing connection?


It's nice to know what system you are trying to connect.Make sure that your script close session correctly. Some systems keep session in case if terminated incorrect. As result you reached maximum amount of concurrent sessions.

  • My system is running Ubuntu 16.04.1 LTS. I've added a snippet from my auth.log. It looks like the sessions are closed properly. netstat -tupn only shows my own active ssh session, no other connection. – JC Lee Feb 21 '17 at 3:54
  • Sniff ssh session with tcpdump on client side. According the logs termination originated by client. If the dump will confirm that, debug the client. – Mancubus Feb 21 '17 at 6:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.