SshPrivateKey
Port forwarder using SSH with a private key for authentication.
Overview
This class sets up a local port forwarding tunnel to a remote host using SSH and a private key file.
Configuration
ssh_user(str): SSH username (default: “ec2-user”)private_key_path(str): Path to the SSH private key file (required)local_host(str): Local host to bind (default: “127.0.0.1”)local_port(int): Local port to bind (default: 0, auto-select)
Example
forwarder = SSHPrivateKey(ssh_user="ec2-user", private_key_path="/path/to/id_rsa")
local_host, local_port = forwarder.setup("db.internal", 3306)
# Use local_host and local_port for DB connection
forwarder.teardown()
ssh_user
Optional
SSH username for authentication (default: “root”).
private_key_path
Optional
Path to the SSH private key file used for authentication.
local_host
Optional
Local host to bind for the forwarding tunnel (default: “127.0.0.1”).
local_port
Optional
Local port to bind for the forwarding tunnel (default: 0, auto-selects a free port).