ssh

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Args added in v0.5.0

func Args(cc ConnConfig) []string

Args builds the SSH command-line arguments for the given connection config. It is exported for use by callers that need to construct custom exec.Cmd with non-standard Stdin/Stdout/Stderr (e.g. sandbox backends).

func Console

func Console(cc ConnConfig, remoteCmd string) error

Console replaces the current process with an interactive SSH session. If remoteCmd is non-empty, it is executed in a forced PTY on the remote host.

func EnvWithOverrides added in v0.6.0

func EnvWithOverrides(base []string, overrides map[string]string) []string

EnvWithOverrides returns a copy of base with entries from overrides added or replaced. Used to inject env vars into the SSH process environment so that SendEnv can forward them.

func Exec

func Exec(ctx context.Context, cc ConnConfig, command []string) (int, error)

Exec runs a command on the remote host via SSH and returns its exit code.

func ExecQuiet added in v0.3.0

func ExecQuiet(ctx context.Context, cc ConnConfig, command []string) (int, error)

ExecQuiet runs a non-interactive command on the remote host via SSH and returns its exit code. Unlike Exec, it does not attach stdin/stdout/stderr.

func Output

func Output(ctx context.Context, cc ConnConfig, command []string) ([]byte, error)

Output runs a command on the remote host via SSH and returns its stdout.

func OutputQuiet added in v0.3.0

func OutputQuiet(ctx context.Context, cc ConnConfig, command []string) ([]byte, error)

OutputQuiet runs a command on the remote host via SSH and returns its stdout, discarding stderr. Use this when parsing command output programmatically.

func RemoveKnownHost added in v0.6.0

func RemoveKnownHost(knownHostsPath, host string) error

RemoveKnownHost removes all entries for the given host from the known_hosts file. This is used to clean up stale entries when containers are created, destroyed, or restored from snapshots. It is a no-op if the known_hosts file does not exist or the path is empty.

func TestAuth

func TestAuth(ctx context.Context, cc ConnConfig) error

TestAuth runs a quick SSH connection test (ssh ... true) to verify key-based authentication works. Returns nil on success.

func WaitReady

func WaitReady(ctx context.Context, host string, timeout time.Duration, log io.Writer) error

WaitReady polls the host's SSH port until it accepts connections or the timeout expires. If log is non-nil, progress is written every 5 seconds.

Types

type ConnConfig added in v0.4.0

type ConnConfig struct {
	Host           string
	User           string
	KeyPath        string
	Env            map[string]string // optional, for SendEnv forwarding
	KnownHostsPath string            // path to known_hosts file for accept-new verification
}

ConnConfig holds the parameters for an SSH connection. Use NewConnConfig to construct — it ensures secure defaults.

func NewConnConfig added in v0.6.0

func NewConnConfig(host, user, keyPath, knownHostsPath string) ConnConfig

NewConnConfig creates a ConnConfig with the given parameters.

Jump to

Keyboard shortcuts

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