ssh

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package ssh provides SSH operations for remote system management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ping

func Ping(host string, port int, timeout time.Duration) bool

Ping checks if the host is reachable

Types

type Client

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

Client handles SSH connections

func NewClient

func NewClient(opts ...ClientOption) *Client

NewClient creates a new SSH client

func (*Client) CheckPort

func (c *Client) CheckPort(ctx context.Context, port int) bool

CheckPort checks if a port is available

func (*Client) Close

func (c *Client) Close() error

Close closes the SSH connection

func (*Client) Connect

func (c *Client) Connect() error

Connect establishes an SSH connection

func (*Client) CopyFile

func (c *Client) CopyFile(ctx context.Context, localPath, remotePath string) error

CopyFile copies a file to the remote host

func (*Client) DirExists

func (c *Client) DirExists(ctx context.Context, remotePath string) bool

DirExists checks if a directory exists on the remote host

func (*Client) FileExists

func (c *Client) FileExists(ctx context.Context, remotePath string) bool

FileExists checks if a file exists on the remote host

func (*Client) GetHost

func (c *Client) GetHost() string

GetHost returns the host

func (*Client) GetSystemInfo

func (c *Client) GetSystemInfo(ctx context.Context) (*models.SystemInfo, error)

GetSystemInfo retrieves system information from the remote host

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns whether the client is connected

func (*Client) MkdirAll

func (c *Client) MkdirAll(ctx context.Context, remotePath string) error

MkdirAll creates a directory and parents on the remote host

func (*Client) ReadFile

func (c *Client) ReadFile(ctx context.Context, remotePath string) ([]byte, error)

ReadFile reads a file from the remote host

func (*Client) Run

func (c *Client) Run(ctx context.Context, command string) (string, string, error)

Run executes a command on the remote host

func (*Client) RunWithSudo

func (c *Client) RunWithSudo(ctx context.Context, command string) (string, string, error)

RunWithSudo runs a command with sudo. Multi-line commands are wrapped in sudo bash -c to ensure all lines run with elevated privileges.

func (*Client) WriteFile

func (c *Client) WriteFile(ctx context.Context, remotePath string, content []byte, mode os.FileMode) error

WriteFile writes content to a file on the remote host

type ClientOption

type ClientOption func(*Client)

ClientOption configures the SSH client

func WithAutoAddHostKeys

func WithAutoAddHostKeys(auto bool) ClientOption

WithAutoAddHostKeys automatically adds unknown host keys

func WithHost

func WithHost(host string) ClientOption

WithHost sets the SSH host

func WithKeyPath

func WithKeyPath(keyPath string) ClientOption

WithKeyPath sets the SSH key path

func WithKnownHostsPath

func WithKnownHostsPath(path string) ClientOption

WithKnownHostsPath sets custom known_hosts file path

func WithPort

func WithPort(port int) ClientOption

WithPort sets the SSH port

func WithSSHTimeout

func WithSSHTimeout(timeout time.Duration) ClientOption

WithSSHTimeout sets the connection timeout

func WithStrictHostKey

func WithStrictHostKey(strict bool) ClientOption

WithStrictHostKey enables strict host key checking

func WithUser

func WithUser(user string) ClientOption

WithUser sets the SSH user

Jump to

Keyboard shortcuts

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