Airflow SSHOperator stops a long script with SSH command timed out
airflow.exceptions.AirflowException: SSH command timed outShort answer
SSHOperator waits only 10 seconds for a command by default. A longer script ends the task with SSH command timed out. Set cmd_timeout on the operator (or None for no limit), and set get_pty=True if the remote process must be killed when the task times out.
Fix it fast
1Find out which cause you have
Check how long the script really runs on the target host, then compare it with the operator's timeout.
time python /opt/jobs/report.py2Match what you see, then jump to its fix
- 1
The task fails with SSH command timed out very soon after it starts, even though the script is healthycmd_timeout is still at its 10 second defaultFix - 2
The task failed with a timeout, but the process is still in ps on the remote machineThe script keeps running on the host after the task timed outFix - 3
Your DAG does not set cmd_timeout, yet the limit differs from the 10 second defaultThe timeout is set in the connection, not in the DAGFix
- 1
What does the error look like?
airflow.exceptions.AirflowException: SSH command timed out
Cause 1 of 3
cmd_timeout is still at its 10 second default
1Check
In the provider, cmd_timeout defaults to 10 seconds, and a null value means no timeout. See whether your task or the connection extras set it.
grep -rn "cmd_timeout" dags/2Fix
Set cmd_timeout on the operator to more than the script's real run time. A value of None removes the limit.
from airflow.providers.ssh.operators.ssh import SSHOperator
run_report = SSHOperator(
task_id="run_report",
ssh_conn_id="report_host",
command="python /opt/jobs/report.py",
cmd_timeout=1800,
)3Verify
Trigger the task and confirm it stays running past 10 seconds and ends with the script's own exit code.
airflow tasks test my_dag run_report 2026-01-01Confirmed by airflow.apache.org
Cause 2 of 3
The script keeps running on the host after the task timed out
1Check
get_pty defaults to False. Without a pseudo-terminal, the remote process is not killed when the task times out.
ssh deploy@report-host 'ps aux | grep report.py'2Fix
Set get_pty=True so the remote process is killed on timeout. The provider forces it on anyway when the command starts with sudo.
run_report = SSHOperator(
task_id="run_report",
ssh_conn_id="report_host",
command="python /opt/jobs/report.py",
cmd_timeout=1800,
get_pty=True,
)3Verify
Force a timeout with a small cmd_timeout on a test run and check no report.py process is left.
ssh deploy@report-host 'pgrep -f report.py || echo none'Confirmed by airflow.apache.org
Cause 3 of 3
The timeout is set in the connection, not in the DAG
1Check
The connection page documents cmd_timeout and conn_timeout as Extra fields. conn_timeout is only for the TCP connect, so raising it does not help a long command.
airflow connections get report_host2Fix
Change cmd_timeout in the connection's Extra JSON, or set it on the operator as above.
{"cmd_timeout": 1800}3Verify
Run the task again and read the task log for the command output.
airflow tasks test my_dag run_report 2026-01-01Confirmed by airflow.apache.org
How do I stop it coming back?
- Set cmd_timeout on every SSHOperator that runs more than a few seconds.
- Use get_pty=True for scripts that must not outlive their task.
- Make the script idempotent so an Airflow retry after a timeout is safe.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
- MenuloA restaurant discovery platform in Germany, kept current by a Python ingestion pipeline.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Back end
Python asyncio: Task was destroyed but it is pending
RuntimeWarning: coroutine '...' was never awaited
A task was still unfinished when Python threw it away.
4 causes, each with a fixBack end
Celery in a Django project does not connect to Redis or ignores the broker URL
kombu.exceptions.InconsistencyError: ... _kombu.binding.celery
Celery talks to Redis through a client library and reads its broker URL from your Django settings.
4 causes, each with a fixBack end
Django form POST returns 403 Forbidden: CSRF verification failed
CSRF verification failed. Request aborted.
Django rejects an unsafe request when the CSRF cookie or the form token is missing or wrong, or when the Origin or Referer check fails.
5 causes, each with a fixBack end
Django cannot import corsheaders (django-cors-headers)
ImportError: No module named corsheaders
The pip package is django-cors-headers, but the module Django imports is corsheaders.
3 causes, each with a fixBack end
Django raises NoReverseMatch when building a URL
NoReverseMatch
NoReverseMatch means Django looked for a named URL pattern that fits the name and arguments you gave and found none.
4 causes, each with a fixBack end
npm install fails inside a node:alpine Docker build
Docker Node Alpine Image Build Fails on node-gyp
The node alpine images ship almost nothing beyond Node.js, so a native module that node-gyp must compile has no Python, make or C++ compiler.
2 causes, each with a fix