config

package
v0.53.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: BSD-3-Clause Imports: 11 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`
	KeyUserKnownHostsFile    = `userknownhostsfile`

	// 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 (
	ValueAcceptNew = `accept-new`
	ValueAlways    = `always`
	ValueAsk       = `ask`
	ValueConfirm   = `confirm`
	ValueOff       = `off`
	ValueNo        = `no`
	ValueNone      = `none`
	ValueYes       = `yes`
)

Known values for key.

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(host string) (section *Section)

Get the Host or Match configuration that match with the host name "s". If no Host or Match found, it return non-nil Section with default values.

func (*Config) Merge added in v0.52.0

func (cfg *Config) Merge(other *Config)

Merge other Config as part of this Config. This function can be used to combine multiple SSH config files into one.

For example after the user's "~/.ssh/config" has been loaded, we can merge it with system "/etc/ssh/ssh_config". During Config.Get the top Config will be evaluated first, and then the other Config is evaluated in order of Merge-d.

type PermittedCNAMEs

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

PermittedCNAMEs contains list of canonical names (CNAME) for source and target.

type Section

type Section struct {
	// Field store the unpacked key and value of Section.
	// For section key that is not expecting string value, one can use
	// FieldBool or FieldInt64.
	Field map[string]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 NewSection added in v0.49.1

func NewSection(cfg *Config, name string) (section *Section)

NewSection create an empty Host or Match section.

The Config parameter is optional, if not set the section will assume that any path is relative to current working directory or using absolute path.

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) FieldInt64 added in v0.50.0

func (section *Section) FieldInt64(key string) (val int64)

FieldInt64 get the Field value as int64. If the value is unparseable as int64 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) MarshalText added in v0.52.0

func (section *Section) MarshalText() (text []byte, err error)

MarshalText encode the Section back to ssh_config format. The key is indented by two spaces.

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.

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.

func (*Section) UserKnownHostsFile added in v0.49.1

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

UserKnownHostsFile return list of user known_hosts file set in this Section.

func (*Section) WriteTo added in v0.52.0

func (section *Section) WriteTo(w io.Writer) (n int64, err error)

WriteTo marshal the Section into text and write it to w.

Jump to

Keyboard shortcuts

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