sshconfig

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0 modules, 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 sshconfig reads OpenSSH client configuration (~/.ssh/config) for import and for the keys a host offers: the Host blocks, with the directives SSHYard keeps (HostName, User, Port, IdentityFile, IdentitiesOnly, ProxyJump), Include, and the defaults of pattern blocks such as Host *. It only reads files; it never writes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Match

func Match(patterns []string, name string) bool

Match reports whether name matches a Host line's patterns: one plain pattern matches and no negated one does.

Types

type Config

type Config struct {

	// Entries are the config's hosts in order, patterns included (marked),
	// Host * left out.
	Entries []Entry
	// Errors are the lines that could not be read, as "file:line: why";
	// they do not stop the parse.
	Errors []string
	// contains filtered or unexported fields
}

Config is a parsed config.

func Parse

func Parse(path string, env Env) (*Config, error)

Parse reads the config at path and the files it includes.

func (*Config) Resolve

func (c *Config) Resolve(name string) Entry

Resolve is the configuration ssh would use for name: each directive from the first block matching it that sets it, IdentityFiles from all. It serves the jump hosts of ProxyJump too, which need not be on a Host line of their own.

type Entry

type Entry struct {
	// Alias is the name on the Host line.
	Alias string
	// HostName is where to connect, the alias when the config names none.
	HostName string
	User     string
	Port     int // 0: not given (22)
	// IdentityFiles are the key files, expanded to absolute paths, in order.
	IdentityFiles []string
	// IdentitiesOnly offers only the IdentityFiles, not the agent's other
	// keys.
	IdentitiesOnly bool
	// ProxyJump is the jump chain, first hop first; nil for none.
	ProxyJump []Hop
	// Unsupported names the directives applying to the host that are not
	// imported, as ProxyCommand or LocalForward, each once.
	Unsupported []string
	// Pattern reports a Host of wildcards (*.corp): it names no one host and
	// is skipped. Host * itself gives defaults and is no entry.
	Pattern bool
	// File and Line are where the Host line is.
	File string
	Line int
}

Entry is one host of the config as ssh would resolve it, defaults of matching pattern blocks included.

type Env

type Env struct {
	Home      string
	LocalUser string
}

Env is what token expansion needs: the local home and user name.

type ErrQuickOption

type ErrQuickOption struct{ Option string }

ErrQuickOption is a command-line option quick connect does not take.

func (*ErrQuickOption) Error

func (e *ErrQuickOption) Error() string

type Hop

type Hop struct {
	User string
	Host string
	Port int // 0: not given
}

Hop is one host of a ProxyJump: [user@]host[:port].

func ParseJump

func ParseJump(s string) []Hop

ParseJump reads a ProxyJump value: comma-separated [user@]host[:port], or ssh:// URIs of the same.

func ParseQuick

func ParseQuick(s string) (Hop, error)

ParseQuick reads what quick connect takes: user@host:port, host, ssh://user@host:port, or an ssh command as "ssh -p 2222 user@host" (-p and -l read, options without an argument ignored).

func ParseTarget

func ParseTarget(s string) (Hop, bool)

ParseTarget reads [user@]host[:port], the host an IPv6 address in brackets when it has a port.

func (Hop) String

func (h Hop) String() string

Jump to

Keyboard shortcuts

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