{"library":"apache-airflow-providers-ssh","code":"import os\nfrom datetime import datetime\nfrom airflow.models.dag import DAG\nfrom airflow.providers.ssh.operators.ssh import SSHOperator\n\n# For local testing, ensure you have an 'ssh_default' connection configured in Airflow UI\n# or via an environment variable, e.g., AIRFLOW_CONN_SSH_DEFAULT=ssh://user@hostname:22/?key_file=/path/to/key\n# For this example, we'll mock the connection_id.\n\n# Example of setting connection details via environment variable for local execution\n# os.environ['AIRFLOW_CONN_SSH_DEFAULT'] = 'ssh://your_user@your_host:22'\n# If using a private key file:\n# os.environ['AIRFLOW_CONN_SSH_DEFAULT'] = 'ssh://your_user@your_host:22?key_file=/path/to/your/private_key.pem'\n\nwith DAG(\n    dag_id='ssh_operator_quickstart',\n    start_date=datetime(2023, 1, 1),\n    schedule_interval=None,\n    catchup=False,\n    tags=['ssh', 'example'],\n) as dag:\n    ssh_task = SSHOperator(\n        task_id='run_remote_command',\n        ssh_conn_id='ssh_default',  # Ensure this connection exists in Airflow\n        command='echo \"Hello from remote host $(hostname)\" && ls -l',\n        cmd_timeout=10,  # Timeout for the command execution\n    )\n","lang":"python","description":"This example demonstrates a basic DAG using the `SSHOperator` to connect to a remote server and execute a shell command. Before running, configure an 'SSH' connection in your Airflow UI (Admin -> Connections) with `Conn Id` as `ssh_default`, providing `Host`, `Login (Username)`, and `Port`. For authentication, you can specify `Password`, `Key File` path, or `Private Key` content in the 'Extra' field as a JSON object (e.g., `{\"key_file\": \"/path/to/your/key.pem\"}`).","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}