Documentation
¶
Overview ¶
Package ssh shells out to the system ssh binary to run commands on a remote host, leaving host-key verification and agent handling to the user's normal SSH configuration.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Output ¶
Output executes remoteCmd on target's host over SSH and returns its captured stdout with leading/trailing whitespace trimmed. Unlike Run, nothing is streamed to the current process's stdout, so this is meant for precondition checks that need to inspect a remote command's output rather than show it to the user. stderr is captured separately and included in the returned error if the command fails.
func Run ¶
func Run(target Target, remoteCmd string, opts RunOptions) error
Run executes remoteCmd on target's host over SSH, streaming the remote command's stdout and stderr through to the current process's stdout and stderr so output is visible to the caller. The current process's stdin is connected through too, so interactive remote prompts (e.g. sudo asking for a password) can be answered.
func WriteFile ¶
WriteFile writes contents to remotePath on target's host over SSH, creating remotePath's parent directory first and chmod'ing the result 644. contents is base64-encoded and piped through the shell rather than streamed, mirroring the approach used elsewhere for shipping small files to a remote host over a single SSH invocation.
Types ¶
type RunOptions ¶
type RunOptions struct {
// TTY allocates a pseudo-terminal for the session (ssh -t), which
// is required for interactive remote prompts such as sudo asking
// for a password.
TTY bool
// Stdin, when set, is streamed to the remote command's stdin
// instead of the current process's stdin. This is what lets
// callers pipe data (e.g. a tar stream) into a remote command
// such as "podman build -".
Stdin io.Reader
}
RunOptions configures how a remote command is executed.
type Target ¶
type Target struct {
// User is the remote account to connect as.
User string
// Host is the SSH host to connect to.
Host string
// Port is the SSH port to connect to. When zero, ssh's default
// (22) is used and no -p flag is emitted.
Port int
// IdentityFile is the path to the SSH private key to authenticate
// with.
IdentityFile string
}
Target identifies the account and host to connect to, and which identity file to authenticate with. Callers pass the identity file appropriate to the account they're connecting as (e.g. a server's AdminIdentityFile for admin operations, or its GitIdentityFile for git-shell operations).
Source Files
¶
- ssh.go