hostkeys

package module
v0.0.0-...-a67b39c Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2019 License: MIT Imports: 7 Imported by: 0

README

hostkeys GoDoc

The hostkeys package provides public ssh host key scanning capability similar to the ssh-keyscan utility.

It complements the golang.org/x/crypto/ssh and golang.org/x/crypto/ssh/knownhosts packages.

Documentation

Overview

Package hostkeys provides public ssh host key scanning capability similar to the ssh-keyscan utility. It complements the golang.org/x/crypto/ssh and golang.org/x/crypto/ssh/knownhosts packages.

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultKeyAlgorithms = []string{
	ssh.KeyAlgoED25519,
	ssh.KeyAlgoRSA,
}

DefaultKeyAlgorithms is the default set of algorithms that will be attempted by Scan.

Functions

func Marshal

func Marshal(entries ...Entry) string

Marshal encodes the given entries as a multiline string compatible with the known_hosts format.

Types

type Entry

type Entry struct {
	Addresses []string
	Key       ssh.PublicKey
}

Entry is an ssh host key.

func Scan

func Scan(addr string, keyAlgorithms ...string) (entries []Entry, err error)

Scan retrieves a set of public ssh host keys from a remote host.

If key algorithms are provided, only keys using those algorithms will be returned. If no key algorithms are provided, DefaultKeyAlgorithms will be used.

Entries supported by the remote will be returned in the same order as the requested key algorithms.

Example
package main

import (
	"fmt"

	"github.com/gentlemanautomaton/hostkeys"
)

func main() {
	keys, err := hostkeys.Scan("github.com")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Print(hostkeys.Marshal(keys...))
}
Output:

func (Entry) String

func (e Entry) String() string

String returns a string representation of the host key that's compatible with the known_hosts file format. The format is defined here: http://man.openbsd.org/sshd.8

Jump to

Keyboard shortcuts

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