Documentation ¶
Overview ¶
Package config provide the ssh_config(5) parser and getter.
Index ¶
- Constants
- type Config
- type PermittedCNAMEs
- type Section
- func (section *Section) CASignatureAlgorithms() []string
- func (section *Section) CanonicalDomains() []string
- func (section *Section) CanonicalizePermittedCNames() (pcnames *PermittedCNAMEs, err error)
- func (section *Section) CertificateFile() []string
- func (section *Section) Environments(sysEnv map[string]string) (env map[string]string)
- func (section *Section) FieldBool(key string) (vbool bool)
- func (section *Section) FieldInt64(key string) (val int64)
- func (section *Section) Hostname() string
- func (section *Section) IdentityAgent() string
- func (section *Section) MarshalText() (text []byte, err error)
- func (section *Section) Port() string
- func (section *Section) Set(key, value string) (err error)
- func (section *Section) Signers() (signers []ssh.Signer, err error)
- func (section *Section) User() string
- func (section *Section) UserKnownHostsFile() []string
- func (section *Section) WriteTo(w io.Writer) (n int64, err error)
Constants ¶
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.
const ( ValueAcceptNew = `accept-new` ValueAlways = `always` ValueAsk = `ask` ValueConfirm = `confirm` ValueOff = `off` ValueNo = `no` ValueNone = `none` ValueYes = `yes` )
Known values for key.
const ( ValueAny = `any` ValueInet = `inet` ValueInet6 = `inet6` )
Valid values for key AddressFamily.
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 (*Config) Get ¶
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
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
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 ¶
CASignatureAlgorithms return list of signature algorithms set from KeyCASignatureAlgorithms. If not set it will return the default CA signature algorithms.
func (*Section) CanonicalDomains ¶
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 ¶
CertificateFile return list of certificate file, if its set in Host or Match configuration.
func (*Section) Environments ¶
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
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
FieldInt64 get the Field value as int64. If the value is unparseable as int64 it will return 0.
func (*Section) IdentityAgent ¶ added in v0.49.0
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
MarshalText encode the Section back to ssh_config format. The key is indented by two spaces.
func (*Section) Signers ¶
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) UserKnownHostsFile ¶ added in v0.49.1
UserKnownHostsFile return list of user known_hosts file set in this Section.