Ssh – way for setting a shorter timeout in an ssh command

sshtimeout

I am writing a Bash script that performs several commands on remote machines via SSH.

The problem is when one of those machines is unreachable, I would like the script to skip and move on instead, it stays stuck until and after a long time it gives a connection timed out.

Is there a way for setting a shorter timeout in an ssh command?

Best Answer

To specify the timeout (in seconds), use the ConnectTimeout option as specified in the ssh_config manual page:

ssh -o ConnectTimeout=10 user@remotehost

To specify the timeout for all hosts, add this configuration to a wildcard stanza in your ssh config file, typically ~/.ssh/config for personal configuration, or /etc/ssh/ssh_config to apply systemwide:

Host *
    ConnectTimeout 10
Related Question