ssh

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 14 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ssh provides strict, profile-based SSH command execution for local NFlow runtimes. Hostnames, usernames, identities, and known_hosts trust are loaded from local profiles; commands are bounded and every host key is checked against OpenSSH known_hosts data.

Package ssh provides profile-based SSH command execution.

Typical use:

profiles, err := ssh.LoadProfiles(ssh.DefaultProfilesPath())
result, err := ssh.RunCommand(ctx, profiles["staging"], "uname -s", 30*time.Second)

Index

Constants

View Source
const (
	DefaultCommandTimeout = 30 * time.Second
	MaxOperationTimeout   = 10 * time.Minute
	MaxCommandOutputBytes = 1 << 20
)

Variables

View Source
var ErrOutputLimit = errors.New("ssh command output exceeded the configured byte limit")

Functions

func DefaultProfilesPath

func DefaultProfilesPath() string

DefaultProfilesPath returns the platform's user config path for SSH profiles.

func LoadProfiles

func LoadProfiles(filename string) (map[string]Profile, error)

LoadProfiles reads and validates a bounded YAML profile file. Relative identity and known_hosts paths are resolved relative to the profile file.

func ValidateTimeout

func ValidateTimeout(timeout time.Duration) (time.Duration, error)

ValidateTimeout applies the command and transfer timeout defaults and hard maximum.

Types

type Client

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

Client owns an SSH connection and any local SSH-agent socket used to authenticate.

func Dial

func Dial(ctx context.Context, profile Profile) (*Client, error)

Dial opens a bounded SSH connection and rejects every host key absent from the profile's OpenSSH known_hosts file. It never enables agent forwarding.

func (*Client) Close

func (c *Client) Close() error

Close closes the SSH connection and its optional local agent connection.

func (*Client) SSHClient

func (c *Client) SSHClient() *cryptossh.Client

SSHClient exposes the underlying client for focused protocol adapters such as SFTP.

type CommandResult

type CommandResult struct {
	Stdout   string        `json:"stdout"`
	Stderr   string        `json:"stderr"`
	ExitCode int           `json:"exit_code"`
	Duration time.Duration `json:"duration"`
}

CommandResult contains bounded command output and the remote process exit code.

func RunCommand

func RunCommand(ctx context.Context, profile Profile, command string, timeout time.Duration) (CommandResult, error)

RunCommand executes one remote shell command with an overall timeout. A non-zero remote exit code is returned in the result; connection and execution failures are returned as errors.

type Profile

type Profile struct {
	Host           string `yaml:"host"`
	Port           int    `yaml:"port"`
	Username       string `yaml:"username"`
	IdentityFile   string `yaml:"identity_file"`
	KnownHostsFile string `yaml:"known_hosts_file"`
	UseAgent       bool   `yaml:"use_agent"`
}

Profile describes one local SSH identity and its strict host-key trust file. Its fields are loaded from a local YAML file, never from an NFlow request.

Jump to

Keyboard shortcuts

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