Documentation
¶
Overview ¶
Package ssh provides SSH client functionality including direct connections, jump host support, and authentication methods (key-based and SSH agent).
Index ¶
- func FormatFingerprint(key ssh.PublicKey) string
- func GetAuthMethods(keyPath string, useAgent bool) ([]ssh.AuthMethod, func(), error)
- func HostKeyCallback() (ssh.HostKeyCallback, error)
- type AgentAuth
- type AuthMethod
- type Client
- func (c *Client) Close() error
- func (c *Client) Connect(ctx context.Context) error
- func (c *Client) Dial(network, addr string) (net.Conn, error)
- func (c *Client) IsConnected() bool
- func (c *Client) Listen(network, addr string) (net.Listener, error)
- func (c *Client) OpenChannel(name string, data []byte) (ssh.Channel, <-chan *ssh.Request, error)
- func (c *Client) SSHClient() *ssh.Client
- type HostKeyVerifier
- type JumpClient
- type KeepAliveConfig
- type KeyAuth
- type SSHClientInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatFingerprint ¶
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 ¶
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) Method ¶
func (a *AgentAuth) Method() ssh.AuthMethod
Method returns the SSH 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) IsConnected ¶
IsConnected returns whether the client is connected
func (*Client) OpenChannel ¶
OpenChannel opens a new channel on the SSH connection
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.
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
type KeepAliveConfig ¶
KeepAliveConfig contains keep-alive settings
type KeyAuth ¶
type KeyAuth struct {
// contains filtered or unexported fields
}
KeyAuth represents SSH key-based authentication
func NewKeyAuth ¶
NewKeyAuth creates a new key-based authentication method
func (*KeyAuth) Method ¶
func (k *KeyAuth) Method() ssh.AuthMethod
Method returns the SSH 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.