ssh

package
v1.123.3 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

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
}

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 Dial

func Dial(ctx context.Context, addr string, opts ...Option) (*Connection, error)

Dial opens a new SSH Connection. Ensure to call Connection.Close() for cleanup.

func (*Connection) Run

func (c *Connection) Run(command string) (io.Reader, io.Reader, error)

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

type Option func(opts *Config) error

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

func WithPrivateKeyBytes(key []byte) Option

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.

func WithUser

func WithUser(user string) Option

WithUser configures the login user.

Jump to

Keyboard shortcuts

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