shellsshtimeout

How to set ssh timeout?


I'm executing a script connecting via password-less SSH on a remote host. I want to set a timeout, so that if the remote host is taking an infinite time to run, I want to come out of that ssh session and continue other lines in my sh script.

How can I set a timeout?


Solution

  • ssh -o ConnectTimeout=10  <hostName>
    

    Where 10 is time in seconds. This Timeout applies only to the creation of the connection.