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?

1 Answer 1


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

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.