ssh

package
v0.0.0-...-634dc1d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tunnel

type Tunnel struct {
	// contains filtered or unexported fields
}

Tunnel manages an SSH tunnel that forwards local connections to a remote host through an SSH server. It opens a local TCP listener on a random port and forwards each accepted connection to the specified remote host:port via the SSH connection.

func NewTunnel

func NewTunnel(sshHost string, sshPort int, sshUser, sshKeyFile, sshPassword string, remoteHost string, remotePort int) (*Tunnel, error)

NewTunnel creates a new SSH tunnel configuration. It connects to the SSH server at sshHost:sshPort using the provided credentials. Authentication methods are tried in order: key file (if provided), SSH agent (if SSH_AUTH_SOCK is set), then password (if provided).

The tunnel will forward local connections to remoteHost:remotePort through the SSH server. Call Start() to begin accepting connections.

func (*Tunnel) LocalPort

func (t *Tunnel) LocalPort() int

LocalPort returns the local port the tunnel listener is bound to. Returns 0 if the tunnel has not been started.

func (*Tunnel) Start

func (t *Tunnel) Start() error

Start opens a local TCP listener on a random port and begins forwarding connections to the remote host through the SSH tunnel. It returns after the listener is ready to accept connections.

func (*Tunnel) Stop

func (t *Tunnel) Stop()

Stop closes the local listener and the SSH connection. It is safe to call multiple times.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL