ssh

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package ssh provides a small SSH client for running remote commands, copying files, and writing env files on a remote host.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option added in v1.2.6

type Option func(opt *clientOptions) error

Option configures the SSH client.

func WithAddr

func WithAddr(addr string, port int) Option

WithAddr sets the host and port to connect to. A port of 0 or less defaults to 22.

func WithHostKey added in v1.2.6

func WithHostKey(publicKey string) Option

WithHostKey pins the remote host key. publicKey is a single line in authorized_keys format (e.g. the output of `ssh-keyscan -t ed25519 host`, host prefix included or not). When this option is not supplied, host key verification is DISABLED, which is only acceptable for hosts you already trust the network path to.

func WithPrivateKey

func WithPrivateKey(envKey string, path string) Option

WithPrivateKey loads the private key from the environment variable envKey, falling back to the file at path when the variable is unset or empty.

func WithPrivateKeyFromEnvKey

func WithPrivateKeyFromEnvKey(envKey string) Option

WithPrivateKeyFromEnvKey loads the private key from the environment variable envKey.

func WithPrivateKeyFromFile

func WithPrivateKeyFromFile(filepath string) Option

WithPrivateKeyFromFile loads the private key from filepath. A leading ~ is expanded to the user's home directory.

func WithTimeout added in v1.2.6

func WithTimeout(d time.Duration) Option

WithTimeout bounds the TCP connection attempt. The default is 30 seconds.

func WithUser

func WithUser(user string) Option

WithUser sets the SSH user.

type RespType

type RespType byte

RespType is the status byte of an scp protocol response.

const (
	Ok RespType = iota
	Warning
	Error
)

type Runner

type Runner interface {
	// CreateEnvFile renders env as KEY=value lines (sorted by key, with
	// ${VAR} references resolved from the local environment) and uploads it
	// to path on the remote host with 0600 permissions.
	CreateEnvFile(path string, env map[string]string) error

	// RunRemote executes cmds sequentially in a single remote shell session,
	// streaming stdout and stderr locally. It returns the first error.
	RunRemote(cmds ...string) error

	// CopyFiles uploads each of filepaths (resolved relative to workspace)
	// into remotePath, creating remotePath if needed. permissions is an
	// octal mode such as "0644"; empty defaults to "0644". Each filepath
	// may contain ${workspace} and ${ENV_VAR} references, which are expanded
	// before glob pattern matching. Filepaths may also be glob patterns
	// (e.g., "*.txt", "bin/*", "${BUILD_DIR}/*.so").
	CopyFiles(permissions, remotePath string, workspace string, filepaths ...string) error

	// Close terminates the underlying SSH connection.
	Close() error
}

Runner is the remote half of the script API.

func Client

func Client(optsFns ...Option) (Runner, error)

Client dials the remote host and returns a Runner. The caller owns the connection and should Close it when done.

Jump to

Keyboard shortcuts

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