config

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2023 License: BSD-3-Clause Imports: 9 Imported by: 1

Documentation

Overview

Package config provide the ssh_config(5) parser and getter.

Index

Constants

View Source
const (
	// List of key in Host or Match with single, string value.
	KeyAddKeysToAgent       = `addkeystoagent`
	KeyAddressFamily        = `addressfamily`
	KeyBindAddress          = `bindaddress`
	KeyBindInterface        = `bindinterface`
	KeyCanonicalizeHostname = `canonicalizehostname`
	KeySetEnv               = `setenv`
	KeyXAuthLocation        = `xauthlocation`

	// List of key in Host or Match with multiple, string values.
	KeyCASignatureAlgorithms = `casignaturealgorithms`
	KeyCanonicalDomains      = `canonicaldomains`
	KeyCertificateFile       = `certificatefile`
	KeyIdentityFile          = `identityfile`
	KeySendEnv               = `sendenv`

	// List of key in Host or Match with integer value.
	KeyCanonicalizeMaxDots = `canonicalizemaxdots`
	KeyConnectTimeout      = `connecttimeout`
	KeyConnectionAttempts  = `connectionattempts`

	// List of key in Host or Match with boolean value.
	KeyBatchMode                       = `batchmode`
	KeyCanonicalizeFallbackLocal       = `canonicalizefallbacklocal`
	KeyChallengeResponseAuthentication = `challengeresponseauthentication`
	KeyCheckHostIP                     = `checkhostip`
	KeyClearAllForwardings             = `clearallforwardings`
	KeyCompression                     = `compression`
	KeyVisualHostKey                   = `visualhostkey`

	// List of key in Host or Match with value fetched using method.
	KeyCanonicalizePermittedCNames = `canonicalizepermittedcnames`
	KeyHostname                    = `hostname`
	KeyIdentityAgent               = `identityagent`
	KeyPort                        = `port`
	KeyUser                        = `user`
)

List of valid keys in Host or Match section.

View Source
const (
	ValueAlways  = `always`
	ValueAsk     = `ask`
	ValueConfirm = `confirm`
	ValueNo      = `no`
	ValueYes     = `yes`
)

Valid values for key AddKeysToAgent.

View Source
const (
	ValueAny   = `any`
	ValueInet  = `inet`
	ValueInet6 = `inet6`
)

Valid values for key AddressFamily.

View Source
const (
	DefConnectionAttempts = `1`
	DefPort               = `22`
	DefXAuthLocation      = `/usr/X11R6/bin/xauth`
)

List of default key value.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config contains mapping of host's patterns and its options from SSH configuration file.

func Load

func Load(file string) (cfg *Config, err error)

Load SSH configuration from file.

func (*Config) Get

func (cfg *Config) Get(s string) (section *Section)

Get the Host or Match configuration that match with the pattern "s". If no Host or Match found, it still return non-nil Section but with empty fields.

func (*Config) Prepend

func (cfg *Config) Prepend(other *Config)

Prepend other Config's sections to this Config. The other's sections will be at the top of the list.

This function can be useful if we want to load another SSH config file without using Include directive.

type PermittedCNAMEs

type PermittedCNAMEs struct {
	// contains filtered or unexported fields
}

type Section

type Section struct {
	// PrivateKeys contains IdentityFile that has been parsed.
	// This field will be set once the Signers has been called.
	PrivateKeys map[string]any

	// Field store the unpacked key and value of Section.
	// For section key that is not expecting string value, one can use
	// FieldBool or FieldInt.
	Field map[string]string

	// The first IdentityFile that exist and valid.
	PrivateKeyFile string

	// WorkingDir contains the directory where the SSH client started.
	// This value is required when client want to copy file from/to
	// remote.
	// This field is optional, default to current working directory from
	// os.Getwd() or user's home directory.
	WorkingDir string

	IdentityFile []string
	// contains filtered or unexported fields
}

Section is the type that represent SSH client Host and Match section in configuration.

func (*Section) CASignatureAlgorithms

func (section *Section) CASignatureAlgorithms() []string

CASignatureAlgorithms return list of signature algorithms set from KeyCASignatureAlgorithms. If not set it will return the default CA signature algorithms.

func (*Section) CanonicalDomains

func (section *Section) CanonicalDomains() []string

CanonicalDomains return list CanonicalDomains set in Section.

func (*Section) CanonicalizePermittedCNames added in v0.49.0

func (section *Section) CanonicalizePermittedCNames() (pcnames *PermittedCNAMEs, err error)

CanonicalizePermittedCNames return the permitted CNAMEs set in Section, from KeyCanonicalizePermittedCNames.

func (*Section) CertificateFile

func (section *Section) CertificateFile() []string

CertificateFile return list of certificate file, if its set in Host or Match configuration.

func (*Section) Environments

func (section *Section) Environments(sysEnv map[string]string) (env map[string]string)

Environments return system and/or custom environment that will be passed to remote machine. The key and value is derived from "SendEnv" and "SetEnv".

func (*Section) FieldBool added in v0.49.0

func (section *Section) FieldBool(key string) (vbool bool)

FieldBool get the Field value as boolean. It will return false if key is not exist or value is invalid.

func (*Section) FieldInt added in v0.49.0

func (section *Section) FieldInt(key string) (vint int)

FieldInt get the Field value as int. It the value is unparseable as numeric it will return 0.

func (*Section) Hostname

func (section *Section) Hostname() string

Hostname return the hostname of this section.

func (*Section) IdentityAgent added in v0.49.0

func (section *Section) IdentityAgent() string

IdentityAgent get the identity agent either from section config variable "IdentityAgent" or from environment variable SSH_AUTH_SOCK.

There are four possible value: SSH_AUTH_SOCK, <$STRING>, <PATH>, or "none". If SSH_AUTH_SOCK, the socket path is read from the environment variable SSH_AUTH_SOCK. If value start with "$", then the socket path is set based on value of that environment variable. Other string beside "none" will be considered as path to socket.

It will return empty string if IdentityAgent set to "none" or SSH_AUTH_SOCK is empty.

func (*Section) Port

func (section *Section) Port() string

Port return the remote machine port of this section.

func (*Section) Set added in v0.49.0

func (section *Section) Set(key, value string) (err error)

Set the section field by raw key and value.

func (*Section) Signers

func (section *Section) Signers() (signers []ssh.Signer, err error)

Signers convert the IdentityFile to ssh.Signer for authentication using PublicKey and store the parsed-unsigned private key into PrivateKeys.

This method will ask for passphrase from terminal, if one of IdentityFile is protected. Unless the value of IdentityFile changes, this method should be called only once, otherwise it will ask passphrase on every call.

func (*Section) User

func (section *Section) User() string

User return the user value of this section.

Jump to

Keyboard shortcuts

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