airflow.providers.ssh.hooks.ssh

Hook for SSH connections.

Module Contents

class airflow.providers.ssh.hooks.ssh.SSHHook(ssh_conn_id: Optional[str] = None, remote_host: Optional[str] = None, username: Optional[str] = None, password: Optional[str] = None, key_file: Optional[str] = None, port: Optional[int] = None, timeout: int = 10, keepalive_interval: int = 30)[source]

Bases: airflow.hooks.base.BaseHook

Hook for ssh remote execution using Paramiko. ref: https://github.com/paramiko/paramiko This hook also lets you create ssh tunnel and serve as basis for SFTP file transfer

Parameters
  • ssh_conn_id (str) – connection id from airflow Connections from where all the required parameters can be fetched like username, password or key_file. Thought the priority is given to the param passed during init

  • remote_host (str) – remote host to connect

  • username (str) – username to connect to the remote_host

  • password (str) – password of the username to connect to the remote_host

  • key_file (str) – path to key file to use to connect to the remote_host

  • port (int) – port of remote host to connect (Default is paramiko SSH_PORT)

  • timeout (int) – timeout for the attempt to connect to the remote_host.

  • keepalive_interval (int) – send a keepalive packet to remote host every keepalive_interval seconds

_default_pkey_mappings[source]
conn_name_attr = ssh_conn_id[source]
default_conn_name = ssh_default[source]
conn_type = ssh[source]
hook_name = SSH[source]
static get_ui_field_behaviour()[source]

Returns custom field behaviour

get_conn(self)[source]

Opens a ssh connection to the remote host.

Return type

paramiko.client.SSHClient

__enter__(self)[source]
__exit__(self, exc_type, exc_val, exc_tb)[source]
get_tunnel(self, remote_port: int, remote_host: str = 'localhost', local_port: Optional[int] = None)[source]

Creates a tunnel between two hosts. Like ssh -L <LOCAL_PORT>:host:<REMOTE_PORT>.

Parameters
  • remote_port (int) – The remote port to create a tunnel to

  • remote_host (str) – The remote host to create a tunnel to (default localhost)

  • local_port (int) – The local port to attach the tunnel to

Returns

sshtunnel.SSHTunnelForwarder object

create_tunnel(self, local_port: int, remote_port: int, remote_host: str = 'localhost')[source]

Creates tunnel for SSH connection [Deprecated].

Parameters
  • local_port – local port number

  • remote_port – remote port number

  • remote_host – remote host

Returns

_pkey_from_private_key(self, private_key: str, passphrase: Optional[str] = None)[source]

Creates appropriate paramiko key for given private key

Parameters

private_key – string containing private key

Returns

paramiko.PKey appropriate for given key

Raises

AirflowException – if key cannot be read

Was this entry helpful?