Documentation
¶
Index ¶
- type Client
- type Config
- type ConfigOption
- func WithAgentAuth() ConfigOption
- func WithEnvVars(envVars map[string]string) ConfigOption
- func WithKeepAlive(keepAlive time.Duration) ConfigOption
- func WithKeyBytesAuth(keyBytes []byte, passphrase string) ConfigOption
- func WithKnownHosts(path string) ConfigOption
- func WithMaxSessions(maxSessions int) ConfigOption
- func WithPasswordAuth(password string) ConfigOption
- func WithPort(p int) ConfigOption
- func WithPrivateKeyPathAuth(path, passphrase string) ConfigOption
- func WithRetry(count int, interval time.Duration) ConfigOption
- func WithSudoPassword(password string) ConfigOption
- func WithTimeout(timeout time.Duration) ConfigOption
- func WithWorkdir(path string) ConfigOption
- type RunOption
- type SCPOption
- type SCPTransfer
- type SFTPOption
- type SFTPTransfer
- type Session
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client runs shell commands over an SSH connection
func NewClient ¶
NewClient dials the SSH server using cfg, retrying on failure, and starts a keepalive loop. Returns an SSH Client or error
func (*Client) OpenSession ¶
OpenSession acquires a session slot, opens a new SSH session, or returns an error
type Config ¶
type Config struct { Host string // *remote host IP or hostname Port int // *SSH port number User string // *SSH username // contains filtered or unexported fields }
Config holds settings for establishing and managing an SSH connection
func NewConfig ¶
func NewConfig(user, host string, port int, opts ...ConfigOption) (*Config, error)
NewConfig creates a Config with required user, host, port and applies any options. Returns an error if any option fails or required fields are invalid
func (*Config) ClientConfig ¶
func (c *Config) ClientConfig() (*ssh.ClientConfig, error)
ClientConfig builds the underlying *ssh.ClientConfig, gathering auth methods in priority order (agent → keyPath/bytes → password) and setting the Host-key callback
type ConfigOption ¶
ConfigOption customizes SSH Config settings
func WithAgentAuth ¶
func WithAgentAuth() ConfigOption
WithAgentAuth enables SSH agent-based authentication
func WithEnvVars ¶
func WithEnvVars(envVars map[string]string) ConfigOption
WithEnvVars merges provided environment variables into the remote session
func WithKeepAlive ¶
func WithKeepAlive(keepAlive time.Duration) ConfigOption
WithKeepAlive sets the TCP keepalive interval
func WithKeyBytesAuth ¶
func WithKeyBytesAuth(keyBytes []byte, passphrase string) ConfigOption
WithKeyBytesAuth enables private key authentication using in-memory key bytes
func WithKnownHosts ¶
func WithKnownHosts(path string) ConfigOption
WithKnownHosts sets the path to a known_hosts file for host key checking
func WithMaxSessions ¶
func WithMaxSessions(maxSessions int) ConfigOption
WithMaxSessions - set max concurrent sessions for connection. You can see it on host in /etc/ssh/sshd_config. Recommend value between 1 and 4
func WithPasswordAuth ¶
func WithPasswordAuth(password string) ConfigOption
WithPasswordAuth enables password-based SSH authentication
func WithPrivateKeyPathAuth ¶
func WithPrivateKeyPathAuth(path, passphrase string) ConfigOption
WithPrivateKeyPathAuth enables private key authentication from a file
func WithRetry ¶
func WithRetry(count int, interval time.Duration) ConfigOption
WithRetry sets connection retry count and interval
func WithSudoPassword ¶
func WithSudoPassword(password string) ConfigOption
WithSudoPassword configures a password for sudo -S on the remote host
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ConfigOption
WithTimeout sets the dial timeout
func WithWorkdir ¶
func WithWorkdir(path string) ConfigOption
WithWorkdir sets the remote working directory
type RunOption ¶
type RunOption func(*runConfig)
RunOption configures a single SSH command execution
func WithEnvVar ¶
WithEnvVar adds or overrides an environment variable for this run
func WithStderr ¶
WithStderr sets a custom writer for live stderr
func WithStdout ¶
WithStdout sets a custom writer for live stdout
func WithStreaming ¶
func WithStreaming() RunOption
WithStreaming enables real-time streaming of stdout and stderr as data arrives
func WithoutBuffering ¶
func WithoutBuffering() RunOption
WithoutBuffering disables internal buffering of output, so only provided stdout/stderr writers receive data
type SCPOption ¶
type SCPOption func(config *scpConfig)
SCPOption customizes scpConfig for a transfer
func WithBufferSize ¶
WithBufferSize sets a custom bufio buffer size
func WithScpBinPath ¶
WithScpBinPath sets a custom scp binary path
type SCPTransfer ¶
type SCPTransfer struct {
// contains filtered or unexported fields
}
SCPTransfer implements FileTransfer by piping data through `scp -t`
func NewSCPTransfer ¶
func NewSCPTransfer(client *Client) *SCPTransfer
NewSCPTransfer initializes an SCPTransfer using an SSH client
type SFTPOption ¶
type SFTPOption func(*sftpConfig)
SFTPOption customizes SFTP transfer behavior
func WithSFTPBufferSize ¶
func WithSFTPBufferSize(n int) SFTPOption
WithSFTPBufferSize sets the buffer size for io.Copy
type SFTPTransfer ¶
type SFTPTransfer struct {
// contains filtered or unexported fields
}
SFTPTransfer implements FileTransfer over SSH using the SFTP subsystem
func NewSFTPTransfer ¶
func NewSFTPTransfer(client *Client) *SFTPTransfer
NewSFTPTransfer creates an SFTPTransfer tied to the given SSH client
func (*SFTPTransfer) Copy ¶
func (t *SFTPTransfer) Copy(ctx context.Context, spec *rexec.FileSpec, opts ...SFTPOption) error
Copy uploads spec.Content to spec.TargetDir on the remote host via SFTP. It creates directories, writes the file, and applies permissions