Sample Header Ad - 728x90

How to forcefully close a ssh connection is the command on the target server never returns

0 votes
1 answer
341 views
I have an automation tool that generates and executes the below command that fires rpm -qa grep httpd on the target host 10.9.100.67.
ssh -vvv -o StrictHostKeyChecking=no -o 'IdentityFile="/app/ssh_keys/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o ConnectTimeout=8 10.9.100.67 'rpm -qa | grep httpd'
Note: the ssh connection command above works fine and I'm able to successfully connect from 10.9.50.20 (source) to target host 10.9.100.67 The problem is with the server 10.9.100.67. If we login to 10.9.100.67 server and fire the rpm -qa | grep httpd it hangs and not even Ctrl+C on my putty shell helps. There is no option but to kill the putty session. The requirement for this post is not to address the rpm -qa | grep httpd hanging on 10.9.100.67 issue; but what I need is my ssh on 10.9.50.20 to close the connection with target 10.9.100.67 if the command does not respond with a failure or success in 5 minutes duration. I even tried the command timeout option but the ssh control does not comeback to source. ssh -vvv -o StrictHostKeyChecking=no -o 'IdentityFile="/app/ssh_keys/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o ConnectTimeout=8 10.9.100.67 'timeout 5s rpm -qa | grep httpd' Note: -o ConnectTimeout=10 does not help and the ssh simply never returns back to 10.9.50.20 from 10.9.100.67 which is what want. Below command from stackoverflow help but does not work for AiX systems as pkill is not present. ssh 10.9.100.67 '( sleep 60 && kill -9 0 ) 2>/dev/null & rpm -qa | grep httpd; RC=$? ; sleep 1 ; pkill -P $! ; exit $RC' Can you help with the solution that works on AIX as well ?
Asked by Ashar (527 rep)
Sep 21, 2020, 11:52 AM
Last activity: Sep 21, 2020, 01:23 PM