A terminal user interface (TUI) application for SSH port forwarding that reads from your local SSH config, allows you to select SSH connections, detects running ports on remote hosts, and forwards them to localhost.
Interactive terminal interface for SSH port forwarding with host selection and port detection
- SSH Config Integration: Automatically reads from
~/.ssh/config - Include Support: Supports SSH config
Includedirective with glob patterns - Full SSH Compatibility: Uses native
sshcommand - supports ProxyCommand, jump hosts, and all SSH features - Interactive Host Selection: Choose from configured SSH hosts using arrow keys
- Automatic Port Detection: Scans remote host for listening ports using
netstat,ss, orlsof - Manual Port Forwarding: Option to manually specify remote ports with improved UI
- Smart Port Mapping: Tries to use same port locally (e.g., remote:3000 → localhost:3000)
- Real-time Port Forwarding: Creates SSH tunnels using
ssh -Lcommand - Clean TUI Interface: Built with Bubble Tea for a smooth terminal experience
go build -o kport-
Run the application:
./kport
-
Test port mapping (optional):
./kport --test-port 3000 # Shows: ✅ Port 3000 available locally - using same port # Mapping: localhost:3000 -> remote:3000
-
Select SSH Host: Use arrow keys to navigate and press Enter to select an SSH host from your config
-
Choose Port:
- The app will automatically detect open ports on the remote host
- Select a port to forward using arrow keys and Enter
- Press 'm' for manual port entry
-
Port Forwarding:
- kport tries to use the same port locally (e.g., remote:3000 → localhost:3000)
- If unavailable, it uses a random available port
- Clear feedback shows the actual mapping and access URLs
↑/↓orj/k: Navigate through SSH hostsEnter: Select host and detect portsm: Manual port forwarding for selected hostq: Quit application
↑/↓orj/k: Navigate through detected portsEnter: Start port forwarding for selected portm: Switch to manual port entryEsc: Go back to host selectionq: Quit application
0-9: Enter port numberBackspace: Delete last digitEnter: Start forwarding for entered portEsc: Go back to previous screenq: Quit application
Esc: Stop forwarding and return to host selectionq: Quit application
The application reads from your standard SSH config file at ~/.ssh/config. Example configuration:
Host my-server
HostName example.com
User myuser
Port 22
IdentityFile ~/.ssh/id_rsa
Host dev-box
HostName dev.example.com
User developer
Port 2222
# Include additional config files
Include ~/.ssh/config.d/*
Include ~/.ssh/work-config
kport supports the SSH Include directive, allowing you to organize your SSH configuration across multiple files:
- Glob patterns:
Include ~/.ssh/config.d/* - Specific files:
Include ~/.ssh/work-config - Relative paths:
Include config.d/servers - Quoted paths:
Include "gitpod/config"orInclude 'path with spaces/config' - Cycle detection: Prevents infinite loops from circular includes
Relative paths in includes are resolved relative to ~/.ssh/ directory, matching OpenSSH behavior.
The application uses the native ssh command, so it supports all SSH authentication methods:
- SSH key-based authentication (using IdentityFile from config)
- SSH agent authentication (if SSH_AUTH_SOCK is set)
- ProxyCommand for jump hosts and SSH containers
- All other SSH configuration options (ControlMaster, etc.)
This means if you can connect with ssh hostname, kport will work too!
- Go 1.19 or later
- SSH access to remote hosts
- SSH config file at
~/.ssh/config
github.com/charmbracelet/bubbletea- TUI frameworkgithub.com/charmbracelet/lipgloss- Terminal stylinggolang.org/x/crypto/ssh- SSH client implementationgolang.org/x/crypto/ssh/agent- SSH agent support
- Config Parsing: Reads and parses your SSH config file to extract host information
- SSH Connection: Uses native
sshcommand with all your configured options - Port Detection: Runs commands like
netstat -tlnpon the remote host via SSH to find listening ports - Port Forwarding: Uses
ssh -L localport:localhost:remoteport hostnamefor tunneling - Full Compatibility: Works with ProxyCommand, jump hosts, SSH containers, and all SSH features
When you select an SSH host:
- Connection Success: Shows detected ports or "No ports detected" with option for manual entry
- Connection Failure: Shows "Could not connect" message with option for manual port forwarding
- Timeout: Connection attempts timeout after 5 seconds to avoid hanging
The application gracefully handles connection failures and allows you to:
- Go back to host selection with
Esc - Try manual port forwarding with
m - Quit with
q
- Requires
sshcommand to be available in PATH - Port detection requires
netstat,ss, orlsofon the remote host - Connection failures are expected for non-existent or unreachable hosts
- Full SSH Feature Support: ProxyCommand, ControlMaster, jump hosts, etc.
- Consistent Behavior: Same authentication and connection logic as your terminal
- SSH Container Support: Works with containers that require ProxyCommand
- No Additional Setup: If
ssh hostnameworks, kport works too
MIT License