ssh

package
v0.0.0-...-5c979af Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendKnownHost

func AppendKnownHost(path, host, authorizedKey string) error

AppendKnownHost appends a known_hosts entry for host using the given authorized key text.

func Dial

func Dial(ctx context.Context, c *Client) (*xssh.Client, error)

Dial establishes an SSH connection using the provided client configuration. The caller is responsible for closing the returned client.

func EnsureKnownHostsFile

func EnsureKnownHostsFile(path string) error

EnsureKnownHostsFile makes sure the directory exists and the file is created.

func GenerateEd25519Keypair

func GenerateEd25519Keypair(privateKeyPath string) (publicAuthorized string, err error)

GenerateEd25519Keypair creates an ed25519 keypair and writes it to disk. The private key is written in PEM format without a passphrase.

func LoadKnownHostsCallback

func LoadKnownHostsCallback(path string) (xssh.HostKeyCallback, error)

LoadKnownHostsCallback returns a strict host key callback using the given file.

func LoadPrivateKeySigner

func LoadPrivateKeySigner(privateKeyPath string) (xssh.Signer, error)

LoadPrivateKeySigner reads an OpenSSH/PEM private key file and returns an ssh.Signer.

func MarshalAuthorized

func MarshalAuthorized(signer xssh.Signer) []byte

MarshalAuthorized returns authorized_keys text for given signer public key.

func PullFile

func PullFile(ctx context.Context, client *xssh.Client, remotePath, localPath string) error

PullFile downloads a remote file to a local path via SFTP.

func PushFile

func PushFile(ctx context.Context, client *xssh.Client, localPath, remotePath string) error

PushFile uploads a local file to a remote path via SFTP.

Types

type Client

type Client struct {
	Addr       string
	User       string
	Signer     xssh.Signer
	KnownHosts xssh.HostKeyCallback
	Timeout    time.Duration
	Retries    int
	Backoff    time.Duration
	Dialer     Dialer
}

func (*Client) RunCommand

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

RunCommand executes a remote command with retries and basic backoff.

type Dialer

type Dialer interface {
	Dial(network, addr string) (net.Conn, error)
}

type NetDialer

type NetDialer struct{ Timeout time.Duration }

func (NetDialer) Dial

func (d NetDialer) Dial(network, addr string) (net.Conn, error)

Jump to

Keyboard shortcuts

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