Documentation
¶
Overview ¶
Package hostkeys reads, writes and collects SSH host keys.
The host key file is the site's trust anchor: it is kept under version control and every connection is checked against it. Editing it with ssh-keygen -R and appending with ssh-keyscan, as the shell tools did, is neither atomic nor locked, so two administrators refreshing at once could lose an entry. Everything here goes through one locked, atomic update.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultAlgorithms = []string{ ssh.KeyAlgoED25519, ssh.KeyAlgoECDSA256, ssh.KeyAlgoRSASHA256, }
DefaultAlgorithms are the host key algorithms collected for a host, best first. Ed25519 is preferred; RSA is kept for service processors and older systems that offer nothing else.
Functions ¶
Types ¶
type Entry ¶
type Entry struct {
// Hosts are the patterns the line applies to.
Hosts []string `json:"hosts" yaml:"hosts"`
// Type is the key algorithm, "ssh-ed25519" and the like.
Type string `json:"type" yaml:"type"`
// Key is the base64 encoded public key.
Key string `json:"key" yaml:"key"`
// Comment is whatever followed the key on the line.
Comment string `json:"comment,omitempty" yaml:"comment,omitempty"`
}
Entry is one line of a known_hosts file.
type File ¶
type File struct {
// Header holds the comment lines at the top of the file, which sites use
// to say what the file is and how it is maintained.
Header []string
// Entries are the host keys.
Entries []Entry
}
File is a parsed known_hosts file: the comment block at the top and the entries under it.
type Scanner ¶
type Scanner struct {
// Algorithms are the key types to ask for, best first.
Algorithms []string
// Timeout bounds one connection attempt.
Timeout time.Duration
// Port is the SSH port; empty means 22.
Port string
// Dial connects; it is replaced in tests.
Dial func(ctx context.Context, network, address string) (net.Conn, error)
}
Scanner collects host keys by starting an SSH handshake and stopping as soon as the server has presented its key.