SshCert
Port forwarder using SSH with a certificate for authentication.
Overview
This class sets up a local port forwarding tunnel to a remote host using SSH and a certificate file.
Configuration
ssh_user(str): SSH username (default: “ec2-user”)cert_path(str): Path to the SSH certificate 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 = SSHCertPort(ssh_user="ec2-user", cert_path="/path/to/cert.pem")
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”).
cert_path
Optional
Path to the SSH certificate 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).