Documentation
¶
Overview ¶
Package ssh provides the connection layer to remote hosts: dialing with agent/key/password auth, ~/.ssh/config respect, known_hosts verification, command execution, and the remote capability probe.
Index ¶
- Constants
- func FirstLine(s string) string
- func ProbedTools() []string
- func ShellQuote(s string) string
- type AuthMethod
- type Capabilities
- type Client
- func (c *Client) Close() error
- func (c *Client) RemoteIP() string
- func (c *Client) Run(ctx context.Context, cmd string) (Result, error)
- func (c *Client) Stream(ctx context.Context, cmd string, w io.Writer) (Result, error)
- func (c *Client) StreamPipe(ctx context.Context, cmd string, stdin io.Reader, w io.Writer) (Result, error)
- type Config
- type Prompter
- type Result
- type Tool
Constants ¶
const DefaultRunTimeout = 10 * time.Minute
DefaultRunTimeout bounds every buffered command (Run): those are bounded by intent — probes, listings, size measurements — and a hung one must not hang a non-interactive run forever. Streamed transfers (Stream) carry no default deadline: dumps and tar pipes legitimately run for hours.
const DefaultTimeout = 15 * time.Second
DefaultTimeout bounds the TCP dial + handshake.
Variables ¶
This section is empty.
Functions ¶
func ProbedTools ¶
func ProbedTools() []string
ProbedTools returns the canonical display order of probed tools.
func ShellQuote ¶
ShellQuote makes s survive a POSIX shell unchanged; see remote.ShellQuote.
Types ¶
type AuthMethod ¶
type AuthMethod string
AuthMethod selects how to authenticate. Empty means auto: agent, then default keys, then password prompt.
const ( AuthAuto AuthMethod = "" AuthAgent AuthMethod = "agent" AuthKey AuthMethod = "key" AuthPassword AuthMethod = "password" )
type Capabilities ¶
type Capabilities = remote.Capabilities
Capabilities is what a remote host offers. See remote.Capabilities.
type Client ¶
type Client struct {
// Config is the resolved configuration the connection was made with.
Config Config
// contains filtered or unexported fields
}
Client is an established SSH connection.
func Dial ¶
Dial resolves cfg against ~/.ssh/config and connects. Host keys are verified against ~/.ssh/known_hosts: unknown hosts go through a TOFU confirmation, changed keys always fail hard.
func (*Client) RemoteIP ¶
RemoteIP is the IP address the connection actually reached — the host's real identity even when Config.Host is an alias or CNAME.
func (*Client) Run ¶
Run executes one command in a fresh session. A non-zero exit status is not a Go error — capability probes expect commands to fail; only transport and session failures are returned as errors. Commands are cut off after DefaultRunTimeout (or the caller's earlier deadline).
func (*Client) Stream ¶
Stream executes cmd, writing its stdout to w as the data arrives — for payloads (database dumps, tar streams) that must never be buffered whole. Result.Stdout stays empty; stderr is captured for diagnostics. Cancelling ctx closes the session (how a capped measurement stops a stream); the bytes written before that remain valid.
func (*Client) StreamPipe ¶
func (c *Client) StreamPipe(ctx context.Context, cmd string, stdin io.Reader, w io.Writer) (Result, error)
StreamPipe is Stream with the command's stdin fed from a reader — the primitive for relays that pipe bytes *into* a remote process (a tar extraction, a NUL-delimited file list). A nil stdin leaves the remote stdin closed, which is exactly Stream.
type Config ¶
type Config struct {
Host string
Port int
User string
Auth AuthMethod
KeyPath string
Timeout time.Duration
// contains filtered or unexported fields
}
Config describes how to reach one host. Host may be a hostname or a ~/.ssh/config alias; zero values are filled by Resolve.
type Prompter ¶
type Prompter interface {
// Password asks for a password or key passphrase.
Password(prompt string) (string, error)
// ConfirmHostKey asks whether to trust an unknown host key (TOFU).
ConfirmHostKey(host, keyType, fingerprint string) (bool, error)
}
Prompter supplies the interactive pieces of dialing. A non-TTY run passes an implementation that fails with remediation guidance instead of hanging.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package remote is the transport-free half of go-ssh: the result type, helpers and capability probe a consumer needs to run commands on a remote host without caring how the connection is made.
|
Package remote is the transport-free half of go-ssh: the result type, helpers and capability probe a consumer needs to run commands on a remote host without caring how the connection is made. |