sshutil

package
v0.75.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package sshutil provides helpers for working with SSH public keys, such as parsing `authorized_keys`-format `.pub` files and matching them against a SHA256 fingerprint (e.g. `SHA256:AbCdEfGhIjKlMnOpQrStUvWxYz0123456789ABCDEF`).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeFingerprint

func NormalizeFingerprint(fingerprint string) string

NormalizeFingerprint adds the "SHA256:" prefix if the caller omitted it.

Types

type KeyInfo

type KeyInfo struct {
	Path        string // filesystem path to the .pub file
	Type        string // e.g. "ssh-ed25519", "ecdsa-sha2-nistp521"
	Comment     string // trailing comment, typically "user@host"
	Fingerprint string // SHA256 fingerprint, e.g. "SHA256:eLpJ..."
}

KeyInfo describes a single parsed SSH public key file.

func FindByFingerprint

func FindByFingerprint(dir, target string) (matches []KeyInfo, errs []error, err error)

FindByFingerprint scans dir for `*.pub` files whose SHA256 fingerprint matches target. The "SHA256:" prefix on target is optional. Files that fail to parse do not abort the search; they are returned via errs.

func ParseAuthorizedKeyFile

func ParseAuthorizedKeyFile(path string) (KeyInfo, error)

ParseAuthorizedKeyFile parses a single `authorized_keys`-format file, such as a `~/.ssh/id_ed25519.pub` file, and returns its KeyInfo.

func ScanDir

func ScanDir(dir string) (keys []KeyInfo, errs []error, err error)

ScanDir parses every `*.pub` file directly inside dir. It does not recurse into subdirectories. Files that fail to parse are skipped for the keys result but reported in errs so callers can surface them rather than having them silently dropped.

Jump to

Keyboard shortcuts

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