Overview
SSH tunneling creates an encrypted connection from your local machine to the database server through one or more intermediate SSH servers. DBHub handles the tunnel setup automatically when you configure SSH parameters. Implementation: src/utils/ssh-tunnel.tsConfiguration Methods
There are three ways to configure SSH tunnels in DBHub:1. TOML Configuration (Recommended)
2. Environment Variables
3. Command-Line Arguments
Authentication Methods
Password Authentication
Private Key Authentication
- Expands
~/to home directory - Resolves symlinks (important on Windows)
- Reads private key file
- Passes key to SSH client
Passphrase-Protected Keys
Default SSH Keys
If nossh_key or ssh_password is provided, DBHub automatically tries default SSH key locations:
~/.ssh/id_rsa~/.ssh/id_ed25519~/.ssh/id_ecdsa~/.ssh/id_dsa
SSH Config File Support
DBHub can read SSH connection parameters from~/.ssh/config:
~/.ssh/config:
- Checks if it looks like an SSH alias (src/utils/ssh-config-parser.ts:177-195)
- Reads
~/.ssh/config - Extracts
HostName,User,Port,IdentityFile,ProxyJump - Merges with explicit TOML configuration
ProxyJump (Multi-Hop SSH)
For databases behind multiple jump hosts, use ProxyJump:ProxyJump Format
Thessh_proxy_jump parameter supports OpenSSH ProxyJump syntax:
Connection Flow
When SSH tunnel is configured:- Parse DSN to extract target database host and port
- Establish SSH tunnel:
- Connect to first jump host (if ProxyJump configured)
- Forward through intermediate jump hosts
- Connect to final SSH host
- Create local port forward to database
- Modify DSN to use local tunnel endpoint (localhost:random_port)
- Connect to database through tunnel
- Clean up tunnel on disconnect
Port Forwarding Mechanics
DBHub uses dynamic port allocation for the local end of the tunnel:Keepalive Configuration
For long-running connections, configure SSH keepalive to prevent timeout:- Sends keepalive packets every 30 seconds
- Disconnects if 3 consecutive keepalives fail (90 seconds total)
- Helps detect broken connections
- Prevents idle timeout on firewalls/NAT devices
Security Considerations
Key-Based Authentication (Recommended)
Best practice: Use SSH keys instead of passwords:Avoid Storing Passwords in Configuration
Bad practice:Restrict SSH User Permissions
On the bastion host, create a limited user for DBHub:Common Scenarios
Connect Through AWS Bastion
Connect Through Azure Bastion
Connect Through GCP Bastion
Multi-Hop Connection (DMZ → Internal Network)
SSH Config with ProxyJump
~/.ssh/config:Troubleshooting
Connection Timeout
Error:SSH connection error: connect ETIMEDOUT
Solutions:
- Verify bastion host is reachable:
- Check firewall rules allow SSH (port 22)
- Verify SSH service is running on bastion
- Test connection manually:
Authentication Failed
Error:SSH connection error: All configured authentication methods failed
Solutions:
- Verify SSH credentials:
- Check private key file permissions (should be 600):
- Verify public key is in
~/.ssh/authorized_keyson bastion - Check SSH user has login permission
- If using passphrase, verify
ssh_passphraseis correct
Permission Denied (publickey)
Error:SSH connection error: Permission denied (publickey)
Solutions:
- Verify public key is installed on bastion:
- Check
~/.ssh/authorized_keyspermissions on bastion (should be 600) - Check home directory permissions on bastion (should not be world-writable)
- Try with password authentication to diagnose:
Port Forwarding Disabled
Error:SSH forward error: Administratively prohibited
Solutions:
- Check SSH server configuration on bastion:
- Restart SSH service after config change:
- Check user-specific restrictions in
Match Userblocks
Cannot Resolve Database Host
Error:SSH forward error: getaddrinfo ENOTFOUND internal-db-host
Solutions:
- Verify database hostname is resolvable from bastion:
- Use IP address instead of hostname in DSN:
- Configure DNS on bastion host
ProxyJump Host Not Found
Error:SSH connection error (jump host 1): ENOTFOUND
Solutions:
- Verify ProxyJump syntax:
- Test jump hosts manually:
- Check each jump host is reachable:
SSH Config Not Found
Error: SSH config file warnings or fallback to defaults Solutions:- Verify SSH config file exists:
- Check file permissions (should be 600):
- On Windows, verify symlinks are resolved:
.sshdirectory may be a junction or symlink- DBHub automatically resolves symlinks (src/utils/ssh-config-parser.ts:34-43)
Tunnel Disconnects After Idle Time
Error: Connection drops after period of inactivity Solutions:- Enable SSH keepalive:
- Configure server-side keepalive in
/etc/ssh/sshd_config: - Check firewall/NAT timeout settings
Private Key Passphrase Incorrect
Error:Error: Encrypted private key detected, but no passphrase given
Solutions:
- Provide passphrase in configuration:
- Or use environment variable:
- Or remove passphrase from key (less secure):
Performance Considerations
Compression
SSH tunnels add overhead. For large data transfers, consider:- Using compression (automatic in SSH)
- Limiting result set size with
maxRows - Using database-native compression (e.g., PostgreSQL’s
ssl_compression)
Connection Pooling
SSH tunnels are persistent per source. DBHub:- Establishes one tunnel per database source
- Reuses tunnel for all queries to that source
- Closes tunnel on disconnect
Latency
Each jump host adds latency:- Direct: ~10-50ms
- Through 1 jump: ~50-150ms
- Through 2 jumps: ~100-300ms