1

Using ssh I am logging to another system and executing scripts there that creates new machines, and do some setups. It takes around 7-8 hours. So what happened is, the ssh connection keeps dropping and I always get timeout with unsuccessful execution of the script.

So now I am using this argument along with ssh connection:

ssh -o ServerAliveInterval=60 user@host ....

This ssh is spawned multiple times. The problem is after few ssh connection, I am getting error :

too many logins of user and the after ssh connections are getting closed just after successful logins.

So is it the behavior of the ServerAliveInterval, that keeps the ssh user login session in remote machine alive even after ssh work is over and that's why my further logins are disconnected?

0

I don't think this keeps a session alive, if your client lost connection. Probably it is those options server side:

ClientAliveCountMax

Sets the number of client alive messages which may be sent without sshd(8) receiving any messages back from the client. If this threshold is reached while client alive messages are being sent, sshd will disconnect the client, terminating the session. It is important to note that the use of client alive messages is very different from TCPKeepAlive. The client alive messages are sent through the encrypted channel and therefore will not be spoofable. The TCP keepalive option enabled by TCPKeepAlive is spoofable. The client alive mechanism is valuable when the client or server depend on knowing when a connection has become inactive.

The default value is 3. If ClientAliveInterval is set to 15, and ClientAliveCountMax is left at the default, unresponsive SSH clients will be disconnected after approximately 45 seconds.

ClientAliveInterval

Sets a timeout interval in seconds after which if no data has been received from the client, sshd(8) will send a message through the encrypted channel to request a response from the client. The default is 0, indicating that these messages will not be sent to the client.

(man sshd_config)

Maybe the real solution to your problem lies in using a terminal multiplexer like screen or tmux. They let your login and the running programs last even if your connection drops. You can reconnect to the terminal at any later point, including the running programs output. Also you can use it to have more than one terminal in your single ssh connection. Since your server seems to limit your ssh sessions, this could be useful as well. You can find one introduction to screen here, but there are tons of others out there.

0

So is it the behavior of the ServerAliveInterval, that keeps the ssh user login session in remote machine alive even after ssh work is over and that's why my further logins are disconnected ?

No. This is sending keepalive messages that checks your connecting and prevents automatic disconnects in SSH or in lower levels. If you want to start long-running scripts, you should use nohup, screen or tmux on the remote side. It will keep your scripts running even after disconnect and with the second two, you can re-attach the existing terminals.

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.