ssh

package
v0.0.0-...-9a5b88c Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package ssh provides SSH client functionality including direct connections, jump host support, and authentication methods (key-based and SSH agent).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatFingerprint

func FormatFingerprint(key ssh.PublicKey) string

FormatFingerprint returns the SHA256 fingerprint of a public key.

func GetAuthMethods

func GetAuthMethods(keyPath string, useAgent bool) ([]ssh.AuthMethod, func(), error)

GetAuthMethods returns authentication methods to try for a given key path It tries key-based auth first, then falls back to agent if available

func HostKeyCallback

func HostKeyCallback() (ssh.HostKeyCallback, error)

HostKeyCallback returns an ssh.HostKeyCallback that verifies host keys against the user's known_hosts file. If the host key is not found, it prompts for confirmation and optionally adds it to known_hosts.

Types

type AgentAuth

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

AgentAuth represents SSH agent-based authentication

func NewAgentAuth

func NewAgentAuth() (*AgentAuth, error)

NewAgentAuth creates a new agent-based authentication method

func (*AgentAuth) Agent

func (a *AgentAuth) Agent() agent.ExtendedAgent

Agent returns the SSH agent client for forwarding

func (*AgentAuth) Close

func (a *AgentAuth) Close() error

Close closes the agent connection

func (*AgentAuth) Method

func (a *AgentAuth) Method() ssh.AuthMethod

Method returns the SSH auth method

func (*AgentAuth) Name

func (a *AgentAuth) Name() string

Name returns the name of this auth method

type AuthMethod

type AuthMethod interface {
	Method() ssh.AuthMethod
	Name() string
}

AuthMethod represents an SSH authentication method

type Client

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

Client represents an SSH client connection

func NewClient

func NewClient(hostConfig config.HostConfig, keepAlive KeepAliveConfig) *Client

NewClient creates a new SSH client

func (*Client) Close

func (c *Client) Close() error

Close closes the SSH connection

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

Connect establishes an SSH connection

func (*Client) Dial

func (c *Client) Dial(network, addr string) (net.Conn, error)

Dial opens a connection to the remote address through the SSH connection

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns whether the client is connected

func (*Client) Listen

func (c *Client) Listen(network, addr string) (net.Listener, error)

Listen creates a listener on the remote SSH server

func (*Client) OpenChannel

func (c *Client) OpenChannel(name string, data []byte) (ssh.Channel, <-chan *ssh.Request, error)

OpenChannel opens a new channel on the SSH connection

func (*Client) SSHClient

func (c *Client) SSHClient() *ssh.Client

SSHClient returns the underlying SSH client

type HostKeyVerifier

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

HostKeyVerifier provides methods to verify and manage host keys.

func NewHostKeyVerifier

func NewHostKeyVerifier() *HostKeyVerifier

NewHostKeyVerifier creates a new host key verifier.

func (*HostKeyVerifier) IsKnown

func (v *HostKeyVerifier) IsKnown(hostname string, port int, key ssh.PublicKey) (bool, error)

IsKnown checks if a host key is known.

type JumpClient

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

JumpClient represents an SSH client that connects through a jump host

func NewJumpClient

func NewJumpClient(hostConfig config.HostConfig, hosts map[string]config.HostConfig, keepAlive KeepAliveConfig) (*JumpClient, error)

NewJumpClient creates a new SSH client that connects through a jump host

func (*JumpClient) Close

func (c *JumpClient) Close() error

Close closes both the main connection and the jump host connection

func (*JumpClient) Connect

func (c *JumpClient) Connect(ctx context.Context) error

Connect establishes an SSH connection through the jump host

type KeepAliveConfig

type KeepAliveConfig struct {
	Enabled  bool
	Interval time.Duration
	Timeout  time.Duration
}

KeepAliveConfig contains keep-alive settings

type KeyAuth

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

KeyAuth represents SSH key-based authentication

func NewKeyAuth

func NewKeyAuth(keyPath string) (*KeyAuth, error)

NewKeyAuth creates a new key-based authentication method

func (*KeyAuth) Method

func (k *KeyAuth) Method() ssh.AuthMethod

Method returns the SSH auth method

func (*KeyAuth) Name

func (k *KeyAuth) Name() string

Name returns the name of this auth method

type SSHClientInterface

type SSHClientInterface interface {
	Connect(ctx context.Context) error
	Close() error
	IsConnected() bool
	Dial(network, addr string) (net.Conn, error)
	Listen(network, addr string) (net.Listener, error)
	SSHClient() *ssh.Client
}

SSHClientInterface defines the interface for SSH client operations. Both Client and JumpClient implement this interface.

func NewSSHClient

func NewSSHClient(hostConfig config.HostConfig, hosts map[string]config.HostConfig, keepAlive KeepAliveConfig) (SSHClientInterface, error)

NewSSHClient creates an appropriate SSH client based on configuration. If the host has a jump host configured, it returns a JumpClient, otherwise it returns a direct Client.

Jump to

Keyboard shortcuts

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