hosts

package
v0.0.0-...-b256af6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hosts describes saved SSH hosts and connects to them: password, private key or the panel's own key authentication, and host keys pinned on first use.

Index

Constants

View Source
const (
	AuthPassword = "password"
	AuthKey      = "key"   // a private key stored with the host
	AuthPanel    = "panel" // the panel's own key (see Keys)
)

Authentication methods.

Variables

View Source
var ErrInvalid = errors.New("invalid host")

ErrInvalid marks a host that fails validation.

Functions

func NewKey

func NewKey(comment string) (string, error)

NewKey generates a panel key: an ed25519 private key in OpenSSH PEM form.

func PublicKey

func PublicKey(privatePEM, comment string) (string, ssh.Signer, error)

PublicKey returns the authorized_keys line of a PEM private key.

Types

type Conn

type Conn struct {
	*ssh.Client
	// HostKey is the server's key in authorized_keys format; the caller
	// pins it when the host had none.
	HostKey string
}

Conn is an authenticated connection.

func Dial

func Dial(ctx context.Context, h Host, panelKey ssh.Signer) (*Conn, error)

Dial connects and authenticates to h. panelKey is the panel's signer, used when h.Auth is AuthPanel.

func (*Conn) KeepAlive

func (c *Conn) KeepAlive(interval time.Duration)

KeepAlive sends keepalive requests until the connection closes, and closes it when the server stops answering, so a dead peer does not leave a terminal hanging.

type Host

type Host struct {
	ID         int64  `json:"id"`
	Name       string `json:"name"`
	Address    string `json:"address"` // host name or IP
	Port       int    `json:"port"`
	User       string `json:"user"`
	Auth       string `json:"auth"`
	Password   string `json:"-"`
	PrivateKey string `json:"-"` // PEM
	Passphrase string `json:"-"` // of PrivateKey, if encrypted
	// HostKey is the server's key pinned on first connection, in
	// authorized_keys format; empty until then.
	HostKey         string    `json:"-"`
	Description     string    `json:"description"`
	LastConnectedAt time.Time `json:"last_connected_at,omitzero"`
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`
}

Host is a saved SSH host. Secrets never leave the server: JSON carries only whether they are set.

func (*Host) Normalize

func (h *Host) Normalize() error

Normalize trims and validates h, filling defaults.

func (Host) View

func (h Host) View() View

View returns h for display.

type HostKeyError

type HostKeyError struct {
	Pinned, Offered string // SHA256 fingerprints
}

HostKeyError reports a server whose key differs from the pinned one: either the server was reinstalled or someone is in between. The operator must forget the pinned key to connect again.

func (*HostKeyError) Error

func (e *HostKeyError) Error() string

type View

type View struct {
	Host
	HasPassword   bool   `json:"has_password"`
	HasKey        bool   `json:"has_key"`
	HostKeyType   string `json:"host_key_type,omitempty"`
	HostKeySHA256 string `json:"host_key_sha256,omitempty"`
}

View is how a host is shown: no secrets, the pinned key's fingerprint.

Jump to

Keyboard shortcuts

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