Documentation ¶
Overview ¶
Package sshtunnel lets you dial (and re-publish locally) SSH-tunneled TCP and Unix domain socket connections using external SSH client processes.
Index ¶
- Constants
- Variables
- func Dial(remoteAddr string, config *Config) (net.Conn, <-chan error, error)
- func DialContext(ctx context.Context, remoteAddr string, config *Config) (net.Conn, <-chan error, error)
- func Listen(laddr net.Addr, raddr string, config *Config) (net.Listener, <-chan error, error)
- func ListenContext(ctx context.Context, laddr net.Addr, raddr string, config *Config) (net.Listener, <-chan error, error)
- type Config
Constants ¶
const CommandTemplateOpenSSHText = `ssh -nNT -L "{{.LocalIP}}:{{.LocalPort}}:{{.RemoteAddr}}" -p "{{.SSHPort}}" "{{.User}}@{{.SSHHost}}" {{.ExtraArgs}}`
CommandTemplateOpenSSHText is a command template text for the openssh `ssh` client binary.
const CommandTemplatePuTTYText = `putty -ssh -NT "{{.User}}@{{.SSHHost}}" -P "{{.SSHPort}}" -L "{{.LocalIP}}:{{.LocalPort}}:{{.RemoteAddr}}" {{.ExtraArgs}}`
CommandTemplatePuTTYText is a command template text for the PuTTY client.
Variables ¶
var CommandTemplateOpenSSH = mustParse(CommandTemplateOpenSSHText)
CommandTemplateOpenSSH is a command template for the openssh `ssh` client binary.
var CommandTemplatePuTTY = mustParse(CommandTemplatePuTTYText)
CommandTemplatePuTTY is a command template for the PuTTY client.
Functions ¶
func Dial ¶
Dial opens a tunnelled connection to the given address using the configured external SSH client.
func DialContext ¶
func DialContext(ctx context.Context, remoteAddr string, config *Config) (net.Conn, <-chan error, error)
DialContext opens a tunnelled connection to the given address using the configured external SSH client and the provided context.
func ListenContext ¶
func ListenContext(ctx context.Context, laddr net.Addr, raddr string, config *Config) (net.Listener, <-chan error, error)
ListenContext serves an SSH tunnel to a remote address on the given local network address `laddr`. The remote endpoint of the tunneled connections is given by the network and addr parameters.
Types ¶
type Config ¶
type Config struct { // SSH user User string // SSH server host SSHHost string // SSH server port SSHPort string // SSH client command template. // A template that may refer to fields from struct commandTemplateData. // Its output is split according to shell splitting rules and executed. CommandTemplate *template.Template // This value will be passed to the CommandTemplate in the ExtraArgs field. CommandExtraArgs string // Optional callback to preform any additional configuration of the SSH client command. CommandConfig func(*exec.Cmd) error // Backoff config used when connecting to the external client. Backoff backoff.Config // Local IP address to listen on (optional). LocalIP *net.IP }
Config is an SSH tunnel configuration using an external SSH client command.