Skip to content
Latchkey

ssh -o BatchMode: Fail Fast Without Prompts

BatchMode=yes turns off passphrase and password prompts so a non-interactive ssh fails cleanly rather than blocking.

A hung job waiting on a hidden prompt is a classic CI failure. BatchMode makes ssh return an error immediately, so the pipeline reports the real problem.

What it does

BatchMode=yes disables querying for passwords and passphrases and other interactive prompts. If authentication needs input that is not available, ssh fails fast with a non-zero exit code instead of waiting on a terminal that does not exist.

Common usage

Terminal
ssh -o BatchMode=yes -i deploy_key user@host "deploy.sh"
# combine with a short timeout so an unreachable host fails quickly
ssh -o BatchMode=yes -o ConnectTimeout=10 user@host "true"

Options

OptionWhat it does
-o BatchMode=yesDisable all interactive prompts; fail instead of asking
-o ConnectTimeout=<sec>Give up if the connection is not made in time
-o PasswordAuthentication=noRefuse password auth, only keys

In CI

Always set BatchMode=yes in pipelines so a key that needs a passphrase, or a server that falls back to a password, fails the step quickly with a clear error instead of hanging until the job times out. Generate CI keys with no passphrase (ssh-keygen -N "").

Common errors in CI

Permission denied (publickey,password). under BatchMode means key auth failed and the password fallback was suppressed, which is the desired fail-fast. "Host key verification failed." still applies because BatchMode does not bypass host key checks. If the key has a passphrase, ssh cannot prompt and fails; use a passphrase-less CI key or an agent.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →