ssh

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: Apache-2.0 Imports: 23 Imported by: 93

Documentation

Overview

Package ssh allows to manage SSH connections and send commands through them.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAuthMethod = errors.New("no authentication method defined")

ErrNoAuthMethod is returned when no authentication method (key pair, agent, or password) is configured on a Host.

Functions

func CheckPrivateSSHConnectionContext added in v1.0.0

func CheckPrivateSSHConnectionContext(t testing.TestingT, ctx context.Context, publicHost *Host, privateHost *Host, command string) string

CheckPrivateSSHConnectionContext attempts to connect to privateHost (which is not addressable from the Internet) via a separate publicHost (which is addressable from the Internet) and then executes "command" on privateHost and returns its output. It is useful for checking that it's possible to SSH from a Bastion Host to a private instance. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.

func CheckPrivateSSHConnectionContextE added in v1.0.0

func CheckPrivateSSHConnectionContextE(t testing.TestingT, ctx context.Context, publicHost *Host, privateHost *Host, command string) (string, error)

CheckPrivateSSHConnectionContextE attempts to connect to privateHost (which is not addressable from the Internet) via a separate publicHost (which is addressable from the Internet) and then executes "command" on privateHost and returns its output. It is useful for checking that it's possible to SSH from a Bastion Host to a private instance. The ctx parameter supports cancellation and timeouts.

func CheckPrivateSshConnection deprecated

func CheckPrivateSshConnection(t testing.TestingT, publicHost Host, privateHost Host, command string) string

CheckPrivateSshConnection attempts to connect to privateHost (which is not addressable from the Internet) via a separate publicHost (which is addressable from the Internet) and then executes "command" on privateHost and returns its output. It is useful for checking that it's possible to SSH from a Bastion Host to a private instance. This will fail the test if the connection fails.

Deprecated: Use CheckPrivateSSHConnectionContext instead.

func CheckPrivateSshConnectionE deprecated

func CheckPrivateSshConnectionE(t testing.TestingT, publicHost Host, privateHost Host, command string) (string, error)

CheckPrivateSshConnectionE attempts to connect to privateHost (which is not addressable from the Internet) via a separate publicHost (which is addressable from the Internet) and then executes "command" on privateHost and returns its output. It is useful for checking that it's possible to SSH from a Bastion Host to a private instance.

Deprecated: Use CheckPrivateSSHConnectionContextE instead.

func CheckSSHCommandContext added in v1.0.0

func CheckSSHCommandContext(t testing.TestingT, ctx context.Context, host *Host, command string) string

CheckSSHCommandContext checks that you can connect via SSH to the given host and run the given command. Returns the stdout/stderr. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.

func CheckSSHCommandContextE added in v1.0.0

func CheckSSHCommandContextE(t testing.TestingT, ctx context.Context, host *Host, command string) (string, error)

CheckSSHCommandContextE checks that you can connect via SSH to the given host and run the given command. Returns the stdout/stderr. The ctx parameter supports cancellation and timeouts.

func CheckSSHCommandWithRetryContext added in v1.0.0

func CheckSSHCommandWithRetryContext(t testing.TestingT, ctx context.Context, host *Host, command string, retries int, sleepBetweenRetries time.Duration, f ...func(testing.TestingT, context.Context, *Host, string) (string, error)) string

CheckSSHCommandWithRetryContext checks that you can connect via SSH to the given host and run the given command until max retries have been exceeded. Returns the stdout/stderr. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.

func CheckSSHCommandWithRetryContextE added in v1.0.0

func CheckSSHCommandWithRetryContextE(t testing.TestingT, ctx context.Context, host *Host, command string, retries int, sleepBetweenRetries time.Duration, f ...func(testing.TestingT, context.Context, *Host, string) (string, error)) (string, error)

CheckSSHCommandWithRetryContextE checks that you can connect via SSH to the given host and run the given command until max retries has been exceeded. Returns an error if the command fails after max retries has been exceeded. The ctx parameter supports cancellation and timeouts.

func CheckSSHConnectionContext added in v1.0.0

func CheckSSHConnectionContext(t testing.TestingT, ctx context.Context, host *Host)

CheckSSHConnectionContext checks that you can connect via SSH to the given host. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.

func CheckSSHConnectionContextE added in v1.0.0

func CheckSSHConnectionContextE(t testing.TestingT, ctx context.Context, host *Host) error

CheckSSHConnectionContextE checks that you can connect via SSH to the given host and returns an error if the connection fails. The ctx parameter supports cancellation and timeouts.

func CheckSSHConnectionWithRetryContext added in v1.0.0

func CheckSSHConnectionWithRetryContext(t testing.TestingT, ctx context.Context, host *Host, retries int, sleepBetweenRetries time.Duration, f ...func(testing.TestingT, context.Context, *Host) error)

CheckSSHConnectionWithRetryContext attempts to connect via SSH until max retries has been exceeded. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.

func CheckSSHConnectionWithRetryContextE added in v1.0.0

func CheckSSHConnectionWithRetryContextE(t testing.TestingT, ctx context.Context, host *Host, retries int, sleepBetweenRetries time.Duration, f ...func(testing.TestingT, context.Context, *Host) error) error

CheckSSHConnectionWithRetryContextE attempts to connect via SSH until max retries has been exceeded and returns an error if the connection fails. The ctx parameter supports cancellation and timeouts.

func CheckSshCommand deprecated

func CheckSshCommand(t testing.TestingT, host Host, command string) string

CheckSshCommand checks that you can connect via SSH to the given host and run the given command. Returns the stdout/stderr. This will fail the test if the connection fails.

Deprecated: Use CheckSSHCommandContext instead.

func CheckSshCommandE deprecated

func CheckSshCommandE(t testing.TestingT, host Host, command string) (string, error)

CheckSshCommandE checks that you can connect via SSH to the given host and run the given command. Returns the stdout/stderr.

Deprecated: Use CheckSSHCommandContextE instead.

func CheckSshCommandWithRetry deprecated added in v0.32.20

func CheckSshCommandWithRetry(t testing.TestingT, host Host, command string, retries int, sleepBetweenRetries time.Duration, f ...func(testing.TestingT, Host, string) (string, error)) string

CheckSshCommandWithRetry checks that you can connect via SSH to the given host and run the given command until max retries have been exceeded. Returns the stdout/stderr. This will fail the test if the connection fails.

Deprecated: Use CheckSSHCommandWithRetryContext instead.

func CheckSshCommandWithRetryE deprecated added in v0.32.20

func CheckSshCommandWithRetryE(t testing.TestingT, host Host, command string, retries int, sleepBetweenRetries time.Duration, f ...func(testing.TestingT, Host, string) (string, error)) (string, error)

CheckSshCommandWithRetryE checks that you can connect via SSH to the given host and run the given command until max retries has been exceeded. Returns an error if the command fails after max retries has been exceeded.

Deprecated: Use CheckSSHCommandWithRetryContextE instead.

func CheckSshConnection deprecated

func CheckSshConnection(t testing.TestingT, host Host)

CheckSshConnection checks that you can connect via SSH to the given host. This will fail the test if the connection fails.

Deprecated: Use CheckSSHConnectionContext instead.

func CheckSshConnectionE deprecated

func CheckSshConnectionE(t testing.TestingT, host Host) error

CheckSshConnectionE checks that you can connect via SSH to the given host and returns an error if the connection fails.

Deprecated: Use CheckSSHConnectionContextE instead.

func CheckSshConnectionWithRetry deprecated added in v0.32.20

func CheckSshConnectionWithRetry(t testing.TestingT, host Host, retries int, sleepBetweenRetries time.Duration, f ...func(testing.TestingT, Host) error)

CheckSshConnectionWithRetry attempts to connect via SSH until max retries has been exceeded. This will fail the test if the connection fails.

Deprecated: Use CheckSSHConnectionWithRetryContext instead.

func CheckSshConnectionWithRetryE deprecated added in v0.32.20

func CheckSshConnectionWithRetryE(t testing.TestingT, host Host, retries int, sleepBetweenRetries time.Duration, f ...func(testing.TestingT, Host) error) error

CheckSshConnectionWithRetryE attempts to connect via SSH until max retries has been exceeded and returns an error if the connection fails.

Deprecated: Use CheckSSHConnectionWithRetryContextE instead.

func Close

func Close(t testing.TestingT, closeable Closeable, ignoreErrors ...string)

Close closes a Closeable.

func FetchContentsOfFile deprecated added in v0.9.17

func FetchContentsOfFile(t testing.TestingT, host Host, useSudo bool, filePath string) string

FetchContentsOfFile connects to the given host via SSH and fetches the contents of the file at the given filePath. If useSudo is true, then the contents will be retrieved using sudo. Returns the contents of that file. This will fail the test if the connection fails.

Deprecated: Use FetchContentsOfFileContext instead.

func FetchContentsOfFileContext added in v1.0.0

func FetchContentsOfFileContext(t testing.TestingT, ctx context.Context, host *Host, useSudo bool, filePath string) string

FetchContentsOfFileContext connects to the given host via SSH and fetches the contents of the file at the given filePath. If useSudo is true, then the contents will be retrieved using sudo. Returns the contents of that file. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.

func FetchContentsOfFileContextE added in v1.0.0

func FetchContentsOfFileContextE(t testing.TestingT, ctx context.Context, host *Host, useSudo bool, filePath string) (string, error)

FetchContentsOfFileContextE connects to the given host via SSH and fetches the contents of the file at the given filePath. If useSudo is true, then the contents will be retrieved using sudo. Returns the contents of that file. The ctx parameter supports cancellation and timeouts.

func FetchContentsOfFileE deprecated added in v0.9.17

func FetchContentsOfFileE(t testing.TestingT, host Host, useSudo bool, filePath string) (string, error)

FetchContentsOfFileE connects to the given host via SSH and fetches the contents of the file at the given filePath. If useSudo is true, then the contents will be retrieved using sudo. Returns the contents of that file.

Deprecated: Use FetchContentsOfFileContextE instead.

func FetchContentsOfFiles deprecated added in v0.9.17

func FetchContentsOfFiles(t testing.TestingT, host Host, useSudo bool, filePaths ...string) map[string]string

FetchContentsOfFiles connects to the given host via SSH and fetches the contents of the files at the given filePaths. If useSudo is true, then the contents will be retrieved using sudo. Returns a map from file path to contents. This will fail the test if the connection fails.

Deprecated: Use FetchContentsOfFilesContext instead.

func FetchContentsOfFilesContext added in v1.0.0

func FetchContentsOfFilesContext(t testing.TestingT, ctx context.Context, host *Host, useSudo bool, filePaths ...string) map[string]string

FetchContentsOfFilesContext connects to the given host via SSH and fetches the contents of the files at the given filePaths. If useSudo is true, then the contents will be retrieved using sudo. Returns a map from file path to contents. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.

func FetchContentsOfFilesContextE added in v1.0.0

func FetchContentsOfFilesContextE(t testing.TestingT, ctx context.Context, host *Host, useSudo bool, filePaths ...string) (map[string]string, error)

FetchContentsOfFilesContextE connects to the given host via SSH and fetches the contents of the files at the given filePaths. If useSudo is true, then the contents will be retrieved using sudo. Returns a map from file path to contents. The ctx parameter supports cancellation and timeouts.

func FetchContentsOfFilesE deprecated added in v0.9.17

func FetchContentsOfFilesE(t testing.TestingT, host Host, useSudo bool, filePaths ...string) (map[string]string, error)

FetchContentsOfFilesE connects to the given host via SSH and fetches the contents of the files at the given filePaths. If useSudo is true, then the contents will be retrieved using sudo. Returns a map from file path to contents.

Deprecated: Use FetchContentsOfFilesContextE instead.

func NoOpHostKeyCallback

func NoOpHostKeyCallback(hostname string, remote net.Addr, key ssh.PublicKey) error

NoOpHostKeyCallback is an ssh.HostKeyCallback that does nothing. Only use this when you're sure you don't want to check the host key at all (e.g., only for testing and non-production use cases).

func SCPDirFromContext added in v1.0.0

func SCPDirFromContext(t testing.TestingT, ctx context.Context, options *SCPDownloadOptions, useSudo bool)

SCPDirFromContext downloads all the files from remotePath on the given host using SCP. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.

func SCPDirFromContextE added in v1.0.0

func SCPDirFromContextE(t testing.TestingT, ctx context.Context, options *SCPDownloadOptions, useSudo bool) error

SCPDirFromContextE downloads all the files from remotePath on the given host using SCP and returns an error if the process fails. Only files within remotePath will be downloaded. This function will not recursively download subdirectories or follow symlinks. The ctx parameter supports cancellation and timeouts.

func SCPFileFromContext added in v1.0.0

func SCPFileFromContext(t testing.TestingT, ctx context.Context, host *Host, remotePath string, localDestination *os.File, useSudo bool)

SCPFileFromContext downloads the file from remotePath on the given host using SCP. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.

func SCPFileFromContextE added in v1.0.0

func SCPFileFromContextE(t testing.TestingT, ctx context.Context, host *Host, remotePath string, localDestination *os.File, useSudo bool) error

SCPFileFromContextE downloads the file from remotePath on the given host using SCP and returns an error if the process fails. The ctx parameter supports cancellation and timeouts.

func SCPFileToContext added in v1.0.0

func SCPFileToContext(t testing.TestingT, ctx context.Context, host *Host, mode os.FileMode, remotePath, contents string)

SCPFileToContext uploads the contents using SCP to the given host. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.

func SCPFileToContextE added in v1.0.0

func SCPFileToContextE(t testing.TestingT, ctx context.Context, host *Host, mode os.FileMode, remotePath, contents string) error

SCPFileToContextE uploads the contents using SCP to the given host and returns an error if the process fails. The ctx parameter supports cancellation and timeouts.

func ScpDirFrom deprecated added in v0.12.1

func ScpDirFrom(t testing.TestingT, options ScpDownloadOptions, useSudo bool)

ScpDirFrom downloads all the files from remotePath on the given host using SCP. This will fail the test if the connection fails.

Deprecated: Use SCPDirFromContext instead.

func ScpDirFromE deprecated added in v0.12.1

func ScpDirFromE(t testing.TestingT, options ScpDownloadOptions, useSudo bool) error

ScpDirFromE downloads all the files from remotePath on the given host using SCP and returns an error if the process fails. Only files within remotePath will be downloaded. This function will not recursively download subdirectories or follow symlinks.

Deprecated: Use SCPDirFromContextE instead.

func ScpFileFrom deprecated added in v0.12.1

func ScpFileFrom(t testing.TestingT, host Host, remotePath string, localDestination *os.File, useSudo bool)

ScpFileFrom downloads the file from remotePath on the given host using SCP. This will fail the test if the connection fails.

Deprecated: Use SCPFileFromContext instead.

func ScpFileFromE deprecated added in v0.12.1

func ScpFileFromE(t testing.TestingT, host Host, remotePath string, localDestination *os.File, useSudo bool) error

ScpFileFromE downloads the file from remotePath on the given host using SCP and returns an error if the process fails.

Deprecated: Use SCPFileFromContextE instead.

func ScpFileTo deprecated added in v0.9.7

func ScpFileTo(t testing.TestingT, host Host, mode os.FileMode, remotePath, contents string)

ScpFileTo uploads the contents using SCP to the given host. This will fail the test if the connection fails.

Deprecated: Use SCPFileToContext instead.

func ScpFileToE deprecated added in v0.9.7

func ScpFileToE(t testing.TestingT, host Host, mode os.FileMode, remotePath, contents string) error

ScpFileToE uploads the contents using SCP to the given host and returns an error if the process fails.

Deprecated: Use SCPFileToContextE instead.

Types

type Closeable

type Closeable interface {
	Close() error
}

Closeable can be closed.

type Host

type Host struct {
	// SshKeyPair is the SSH key pair to use for authentication. Disabled by default.
	SshKeyPair *KeyPair //nolint:staticcheck,revive // preserving existing field name
	// OverrideSshAgent enables an in-process [SSHAgent] for connections to this host. Disabled by default.
	OverrideSshAgent *SSHAgent //nolint:staticcheck,revive // preserving existing field name
	// Hostname is the host name or IP address.
	Hostname string
	// SshUserName is the SSH user name.
	SshUserName string //nolint:staticcheck,revive // preserving existing field name
	// Password is the plain text password for authentication. Blank by default.
	Password string
	// CustomPort is the port number to use to connect to the host. Port 22 is used if unset.
	CustomPort int
	// SshAgent enables authentication using the existing local SSH agent. Disabled by default.
	SshAgent bool //nolint:staticcheck,revive // preserving existing field name
}

Host is a remote host. Set one or more authentication methods on the host; the first valid method will be used.

func (*Host) GetPort added in v1.0.0

func (h *Host) GetPort() int

GetPort returns the port to use for SSH connections. If [Host.CustomPort] is set, it returns that value; otherwise, it returns the default SSH port 22.

type JumpHostSession

type JumpHostSession struct {
	// JumpHostClient is the SSH client for the jump host.
	JumpHostClient *ssh.Client
	// HostVirtualConnection is the virtual connection to the target host through the jump host.
	HostVirtualConnection net.Conn
	// HostConnection is the SSH connection to the target host.
	HostConnection ssh.Conn
}

JumpHostSession is a session with a jump host used for tunneling SSH connections.

func (*JumpHostSession) Cleanup

func (jumpHost *JumpHostSession) Cleanup(t testing.TestingT)

Cleanup cleans the jump host session up.

type KeyPair

type KeyPair struct {
	// PublicKey is the SSH public key in authorized_keys format.
	PublicKey string
	// PrivateKey is the PEM-encoded SSH private key.
	PrivateKey string
}

KeyPair is a public and private key pair that can be used for SSH access.

func GenerateRSAKeyPair

func GenerateRSAKeyPair(t testing.TestingT, keySize int) *KeyPair

GenerateRSAKeyPair generates an RSA Keypair and return the public and private keys.

func GenerateRSAKeyPairE

func GenerateRSAKeyPairE(t testing.TestingT, keySize int) (*KeyPair, error)

GenerateRSAKeyPairE generates an RSA Keypair and return the public and private keys.

type SCPDownloadOptions added in v1.0.0

type SCPDownloadOptions struct {
	// RemoteDir is the directory on the remote machine to copy files from.
	RemoteDir string
	// LocalDir is the directory on the local machine to copy files to.
	LocalDir string
	// FileNameFilters are file name patterns to match. May include bash-style wildcards (e.g., *.log).
	FileNameFilters []string
	// RemoteHost is the connection information for the remote machine.
	RemoteHost Host
	// MaxFileSizeMB is the maximum file size in megabytes to download. Files larger than this are skipped.
	MaxFileSizeMB int
}

SCPDownloadOptions configures the parameters for downloading files from a remote host via SCP.

type SSHAgent added in v1.0.0

type SSHAgent struct {
	// contains filtered or unexported fields
}

SSHAgent is an in-process SSH agent that can be used for SSH authentication in tests.

func NewSSHAgent added in v1.0.0

func NewSSHAgent(t testing.TestingT, ctx context.Context, socketDir string, socketFile string) (*SSHAgent, error)

NewSSHAgent creates an SSH agent, starts it in the background, and returns control back to the main thread. You should stop the agent to clean up files afterwards by calling defer s.Stop(). The ctx parameter is used when establishing the Unix socket listener.

func NewSshAgent deprecated added in v0.10.1

func NewSshAgent(t testing.TestingT, socketDir string, socketFile string) (*SSHAgent, error)

NewSshAgent creates an SSH agent, starts it in the background, and returns control back to the main thread. You should stop the agent to clean up files afterwards by calling defer s.Stop().

Deprecated: Use NewSSHAgent instead.

func SSHAgentWithKeyPair added in v1.0.0

func SSHAgentWithKeyPair(t testing.TestingT, ctx context.Context, keyPair *KeyPair) *SSHAgent

SSHAgentWithKeyPair creates and returns an in-memory SSH agent with the given KeyPair already added. You should stop the agent to clean up files afterwards by calling defer sshAgent.Stop(). This will fail the test if there is an error. The ctx parameter is used when establishing the Unix socket listener.

func SSHAgentWithKeyPairE added in v1.0.0

func SSHAgentWithKeyPairE(t testing.TestingT, ctx context.Context, keyPair *KeyPair) (*SSHAgent, error)

SSHAgentWithKeyPairE creates and returns an in-memory SSH agent with the given KeyPair already added. You should stop the agent to clean up files afterwards by calling defer sshAgent.Stop(). The ctx parameter is used when establishing the Unix socket listener.

func SSHAgentWithKeyPairs added in v1.0.0

func SSHAgentWithKeyPairs(t testing.TestingT, ctx context.Context, keyPairs []*KeyPair) *SSHAgent

SSHAgentWithKeyPairs creates and returns an in-memory SSH agent with the given KeyPairs already added. You should stop the agent to clean up files afterwards by calling defer sshAgent.Stop(). This will fail the test if there is an error. The ctx parameter is used when establishing the Unix socket listener.

func SSHAgentWithKeyPairsE added in v1.0.0

func SSHAgentWithKeyPairsE(t testing.TestingT, ctx context.Context, keyPairs []*KeyPair) (*SSHAgent, error)

SSHAgentWithKeyPairsE creates and returns an in-memory SSH agent with the given KeyPairs already added. You should stop the agent to clean up files afterwards by calling defer sshAgent.Stop(). The ctx parameter is used when establishing the Unix socket listener.

func SshAgentWithKeyPair deprecated added in v0.10.1

func SshAgentWithKeyPair(t testing.TestingT, keyPair *KeyPair) *SSHAgent

SshAgentWithKeyPair creates and returns an in-memory SSH agent with the given KeyPair already added. You should stop the agent to clean up files afterwards by calling defer sshAgent.Stop(). This will fail the test if there is an error.

Deprecated: Use SSHAgentWithKeyPair instead.

func SshAgentWithKeyPairE deprecated added in v0.10.1

func SshAgentWithKeyPairE(t testing.TestingT, keyPair *KeyPair) (*SSHAgent, error)

SshAgentWithKeyPairE creates and returns an in-memory SSH agent with the given KeyPair already added. You should stop the agent to clean up files afterwards by calling defer sshAgent.Stop().

Deprecated: Use SSHAgentWithKeyPairE instead.

func SshAgentWithKeyPairs deprecated added in v0.10.1

func SshAgentWithKeyPairs(t testing.TestingT, keyPairs []*KeyPair) *SSHAgent

SshAgentWithKeyPairs creates and returns an in-memory SSH agent with the given KeyPairs already added. You should stop the agent to clean up files afterwards by calling defer sshAgent.Stop(). This will fail the test if there is an error.

Deprecated: Use SSHAgentWithKeyPairs instead.

func SshAgentWithKeyPairsE deprecated added in v0.10.1

func SshAgentWithKeyPairsE(t testing.TestingT, keyPairs []*KeyPair) (*SSHAgent, error)

SshAgentWithKeyPairsE creates and returns an in-memory SSH agent with the given KeyPairs already added. You should stop the agent to clean up files afterwards by calling defer sshAgent.Stop().

Deprecated: Use SSHAgentWithKeyPairsE instead.

func (*SSHAgent) Agent added in v1.0.0

func (s *SSHAgent) Agent() agent.Agent

Agent returns the underlying ssh agent.Agent used by this SSHAgent.

func (*SSHAgent) SocketDir added in v1.0.0

func (s *SSHAgent) SocketDir() string

SocketDir returns the path to the directory containing the SSH agent's Unix socket.

func (*SSHAgent) SocketFile added in v1.0.0

func (s *SSHAgent) SocketFile() string

SocketFile returns the path to the SSH agent's Unix socket file.

func (*SSHAgent) Stop added in v1.0.0

func (s *SSHAgent) Stop()

Stop stops the SSH agent, closes its listener, and removes the socket directory.

type SSHConnectionOptions added in v1.0.0

type SSHConnectionOptions struct {
	// JumpHost is the optional jump host connection options for tunneling.
	JumpHost *SSHConnectionOptions
	// Username is the SSH user name.
	Username string
	// Address is the host address.
	Address string
	// Command is the command to run on the remote host.
	Command string
	// AuthMethods are the SSH authentication methods to use.
	AuthMethods []ssh.AuthMethod
	// Port is the SSH port number.
	Port int
}

SSHConnectionOptions are the options for an SSH connection.

func (*SSHConnectionOptions) ConnectionString added in v1.0.0

func (options *SSHConnectionOptions) ConnectionString() string

ConnectionString returns the connection string for an SSH connection.

type SSHSession added in v1.0.0

type SSHSession struct {
	// Options are the SSH connection options.
	Options *SSHConnectionOptions
	// Client is the SSH client.
	Client *ssh.Client
	// Session is the SSH session.
	Session *ssh.Session
	// JumpHost is the optional jump host session for tunneling.
	JumpHost *JumpHostSession
	// Input is an optional function that writes to the session's stdin pipe.
	Input *func(io.WriteCloser)
}

SSHSession is a container object for all resources created by an SSH session. The reason we need this is so that we can do a single defer in a top-level method that calls the Cleanup method to go through and ensure all of these resources are released and cleaned up.

func (*SSHSession) Cleanup added in v1.0.0

func (sshSession *SSHSession) Cleanup(t testing.TestingT)

Cleanup cleans up an existing SSH session.

type ScpDownloadOptions deprecated added in v0.12.1

type ScpDownloadOptions = SCPDownloadOptions //nolint:staticcheck,revive // preserving deprecated type name

ScpDownloadOptions is a backwards-compatible alias for SCPDownloadOptions.

Deprecated: Use SCPDownloadOptions instead.

type SshAgent deprecated added in v0.10.1

type SshAgent = SSHAgent //nolint:staticcheck,revive // preserving deprecated type name

SshAgent is a backwards-compatible alias for SSHAgent.

Deprecated: Use SSHAgent instead.

type SshConnectionOptions deprecated

type SshConnectionOptions = SSHConnectionOptions //nolint:staticcheck,revive // preserving deprecated type name

SshConnectionOptions is a backwards-compatible alias for SSHConnectionOptions.

Deprecated: Use SSHConnectionOptions instead.

type SshSession deprecated

type SshSession = SSHSession //nolint:staticcheck,revive // preserving deprecated type name

SshSession is a backwards-compatible alias for SSHSession.

Deprecated: Use SSHSession instead.

Jump to

Keyboard shortcuts

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