ssh

package
v0.0.0-...-9994f1b Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPort = 22

Variables

View Source
var SSHSigner ssh.Signer

SSHSigner public key

Functions

func Run

func Run(ctx context.Context, provider SSHProvider, addr string, cmd string) (result *tlw.RunResult)

Run executes command on the target address by SSH.

func RunBackground

func RunBackground(ctx context.Context, provider SSHProvider, addr string, cmd string) (result *tlw.RunResult)

RunBackground executes command on the target address by SSH in background.

Types

type Config

type Config interface {
	// Load implements reading configuration from the given ssh_config file
	Load(sshConfigPath string) error
	// GetProxy returns proxy configuration used to establish SSH tunnel.
	GetProxy(host string) *proxyConfig
	// GetSSHConfig returns ssh ClientConfig.
	GetSSHConfig(host string) *ssh.ClientConfig
}

Config is the interface that wraps the SSH and TLS configurations

func NewDefaultConfig

func NewDefaultConfig(keyPaths []string) (Config, error)

NewDefaultConfig creates a new instance of Config structure and populates it with the default SSH config.

type Forwarder

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

Forwarder creates a listener that forwards TCP connections to another host over an already-established SSH connection.

A pictoral explanation:

               Local               |    SSH Host    |   Remote
-----------------------------------+----------------+-------------

(local-to-remote)

[client] <- TCP -> [Forwarder] <- SSH -> [sshd] <- TCP -> [server]

(remote-to-local)

[server] <- TCP -> [Forwarder] <- SSH -> [sshd] <- TCP -> [client]

func (*Forwarder) Close

func (f *Forwarder) Close() error

Close stops listening for incoming connections.

func (*Forwarder) ListenAddr

func (f *Forwarder) ListenAddr() net.Addr

ListenAddr returns the address used to listen for connections.

func (*Forwarder) LocalAddr

func (f *Forwarder) LocalAddr() net.Addr

LocalAddr returns the address used to listen for connections. Deprecated. Use ListenAddr instead.

type SSHClient

type SSHClient interface {
	NewSession() (*ssh.Session, error)
	IsAlive() bool
	Close() error
	Client() *ssh.Client
	ForwardLocalToRemote(localAddr, remoteAddr string, errFunc func(error)) (*Forwarder, error)
}

SSHClient provides base API to work with SSH client.

func NewClient

func NewClient(ctx context.Context, addr, username string, config Config) (SSHClient, error)

NewClient starts a client connection to the given SSH host.

type SSHProvider

type SSHProvider interface {
	Get(ctx context.Context, addr string) (SSHClient, error)
	CloseClient(ctx context.Context, c SSHClient) error
	Close() error
	Config() Config
	SetUser(username string)
	UseClientPool() bool
	Clone() SSHProvider
}

SSHProvider provide access to SSH client manager.

Provider gives option to use pool or create new client always.

func NewProvider

func NewProvider(config Config) SSHProvider

NewProvider creates new provider for use.

clientConfig: SSH configuration to configure the new clients.
tlsConfig: Optional TLS configuration to establish SSH connections over TLS channel.

Jump to

Keyboard shortcuts

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