sshclient

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 17 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 sshclient runs commands with the system OpenSSH client, using explicit identities and pinned host keys.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fingerprint

func Fingerprint(ctx context.Context, id Identity, tempRoot string) (string, error)

Fingerprint validates an imported private key using OpenSSH without putting its passphrase in argv.

func HostFingerprint

func HostFingerprint(key string) (string, error)

func ScanHostKey

func ScanHostKey(ctx context.Context, host string, port int) (string, error)

ScanHostKey fetches the host's public key for trust on first use, preferring ed25519, then ECDSA, then RSA.

func Validate

func Validate(c *Config) error

Validate checks a complete configuration, including the pinned host key.

func ValidateAddress

func ValidateAddress(c *Config) error

ValidateAddress checks everything except the host key, for hosts whose key is trusted on first connection.

Types

type Config

type Config struct {
	Host     string `json:"host"`
	Port     int    `json:"port"`
	User     string `json:"user"`
	SecretID string `json:"secretID"`
	HostKey  string `json:"hostKey"`
	Sudo     bool   `json:"sudo"`
}

type Identity

type Identity struct {
	PrivateKey string `json:"privateKey"`
	Passphrase string `json:"passphrase,omitempty"`
}

type Session

type Session struct {
	Config Config
	// contains filtered or unexported fields
}

func New

func New(c Config, id Identity, tempRoot string) (*Session, error)

func (*Session) Close

func (s *Session) Close()

func (*Session) Run

func (s *Session) Run(ctx context.Context, command string, input io.Reader) ([]byte, error)

Run returns the last 64 KiB of the command's stdout, also when it fails. Remote stderr is discarded unless the command redirects it: a remote shell can echo secrets read from stdin. OpenSSH's own messages go to a separate -E log, which is safe to report.

func (*Session) Stream

func (s *Session) Stream(ctx context.Context, command string, input io.Reader, w io.Writer) error

Stream runs command with stdout copied to w in full, for file transfers.

type Shell

type Shell struct {
	Stdin  io.WriteCloser
	Stdout io.Reader
	// contains filtered or unexported fields
}

Shell is an interactive login shell with a pseudo-terminal, for the browser console. Scripted work keeps using Run with the OpenSSH client.

func OpenShell

func OpenShell(ctx context.Context, c Config, id Identity, cols, rows int) (*Shell, error)

OpenShell connects with the pinned host key and starts a login shell.

func (*Shell) Close

func (s *Shell) Close()

func (*Shell) Resize

func (s *Shell) Resize(cols, rows int) error

Resize changes the remote terminal size.

func (*Shell) Wait

func (s *Shell) Wait() error

Wait returns when the remote shell exits.

type System

type System struct {
	Host string
	Port int    // 0 uses ~/.ssh/config or 22
	User string // "" uses ~/.ssh/config or the local user name
	// ConfigFile replaces ~/.ssh/config, for example in CI.
	ConfigFile string
	// IdentityFile is the only private key offered when set. A key with a
	// passphrase must be loaded into ssh-agent: Korta never prompts.
	IdentityFile string
}

System connects with the user's own OpenSSH setup: ~/.ssh/config, ssh-agent and ~/.ssh/known_hosts. Unknown or changed host keys are refused rather than trusted, and it never asks for passwords.

func (System) Run

func (s System) Run(ctx context.Context, command string, input io.Reader) ([]byte, error)

Run returns the last 64 KiB of the command's stdout, also when it fails.

Jump to

Keyboard shortcuts

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