Documentation
¶
Index ¶
- func SingleKnownHost() ssh.HostKeyCallback
- type Config
- type Connection
- func (c *Connection) Copy(ctx context.Context, remotePath, permissions string, data []byte) error
- func (c *Connection) CopyFile(ctx context.Context, remotePath, permissions string, file fs.File) error
- func (c *Connection) Run(command string) (io.Reader, io.Reader, error)
- func (c *Connection) RunWithStreams(stdin io.Reader, stdout, stderr io.Writer, command string) error
- type Option
- type PrefixedWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SingleKnownHost ¶
func SingleKnownHost() ssh.HostKeyCallback
SingleKnownHost is a simple HostKeyCallback that stores the host key in memory on the first callback. Future callbacks verify that the host key hasn't changed.
Types ¶
type Config ¶
type Config struct {
// ClientConfig is the standard SSH client config.
ssh.ClientConfig
// DialContext is used for opening TCP connections to the remote host. Defaults to a net.Dialer with 30s timeout.
DialContext func(ctx context.Context, network, addr string) (net.Conn, error)
}
Config contains configuration for connecting to remote hosts.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig is the default SSH client Config used by Dial.
type Connection ¶
type Connection struct {
*ssh.Client
SCP *scp.Client
// OutputPrefix is an optional line prefix added to stdout and stderr in Run and RunWithStreams.
// This is useful when dealing with multiple connections for marking output with different connection information.
OutputPrefix string
}
Connection simplifies working with SSH connections for standard command execution and connection proxying. Use Dial to open a new Connection, and ensure to call Connection.Close() for cleanup.
func (*Connection) Copy ¶ added in v1.126.0
Copy copies the given bytes to a file at remotePath with the given permissions.
func (*Connection) CopyFile ¶ added in v1.126.0
func (c *Connection) CopyFile(ctx context.Context, remotePath, permissions string, file fs.File) error
CopyFile copies the file to remotePath with the given permissions.
func (*Connection) Run ¶
Run executes the given command on the remote host and returns stdout and stderr streams.
func (*Connection) RunWithStreams ¶
func (c *Connection) RunWithStreams(stdin io.Reader, stdout, stderr io.Writer, command string) error
RunWithStreams executes the given command on the remote host with the configured streams.
type Option ¶
Option is an option that can be passed to Dial for customizing the client Config.
func WithPrivateKey ¶
func WithPrivateKey(key *rsa.PrivateKey) Option
WithPrivateKey configures the client to authenticate using the given RSA private key.
func WithPrivateKeyBytes ¶
WithPrivateKeyBytes configures the client to authenticate using the given PEM encoded private key.
func WithProxyConnection ¶
func WithProxyConnection(conn *Connection) Option
WithProxyConnection configures the client to open the new TCP connection to the remote host via another open SSH connection.
type PrefixedWriter ¶ added in v1.126.0
type PrefixedWriter struct {
// contains filtered or unexported fields
}
PrefixedWriter wraps an io.Writer, emitting the passed in prefix at the beginning of each new line. This can be useful when running multiple ssh.Connections concurrently - you can prefix the log output of each session by passing in a PrefixedWriter. This is used by Connection.OutputPrefix.
func NewPrefixedWriter ¶ added in v1.126.0
func NewPrefixedWriter(prefix string, writer io.Writer) *PrefixedWriter
NewPrefixedWriter creates a new PrefixedWriter.