I am using Python Paramiko ssh.exec_command to send commands to a slave machine from the master machine (from CentOS to CentOS). The master sends the command to the slave and waits (sleeps or does something meaningful) for it to be completed by the slave. The slave takes approximately 10 hours to complete the command. After 10 hours if the master sends the next command to the slave using ssh.exec_command, I get an error message saying SSH session is not active.
I tried setting ServerAliveinterval, TCPKeepAlive in ssh_config file on both master and slave side. But nothing worked. What are all the other possibilities that I need to check to keep the SSH session active forever.
ServerAliveInterval has no effect on Paramiko.
Use Transport.set_keepalive:
transport = client.get_transport()
transport.set_keepalive(60)
If that does not help (typically because the server ignores keepalives), you have to keep the session alive yourself. E.g. by making the command produce an output continuously.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With