ssh_config

package module
v0.0.0-...-abe4e32 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2018 License: MIT Imports: 10 Imported by: 0

README

ssh_config

a simple ssh config parser/writer lib

Example:

ssh_config_file := os.ExpandEnv("$HOME/.ssh/config")

file, err := os.Open(ssh_config_file)
if err != nil {
	log.Fatal(err)
}

config, err := ssh_config.Parse(file)
if err != nil {
	log.Fatal(err)
}

file.Close()

// modify by reference for existing params
// or create a new param and append it to global
if param := config.GetParam(ssh_config.VisualHostKeyKeyword); param != nil {
	param.Args = []string{"yes"}
} else {
	param = ssh_config.NewParam(ssh_config.VisualHostKeyKeyword, []string{"yes"}, []string{"good to see you"})
	config.Globals = append(config.Globals, param)
}

// atomic write to file to ensure config is preserved in
// the event of an error
if err := config.WriteToFilepath(ssh_config_file); err != nil {
	log.Fatal(err)
}

Documentation

License: MIT

Documentation

Index

Constants

View Source
const (
	HostKeyword                             = "Host"
	MatchKeyword                            = "Match"
	AddressFamilyKeyword                    = "AddressFamily"
	BatchModeKeyword                        = "BatchMode"
	BindAddressKeyword                      = "BindAddress"
	CanonicalDomainsKeyword                 = "CanonicalDomains"
	CanonicalizeFallbackLocalKeyword        = "CanonicalizeFallbackLocal"
	CanonicalizeHostnameKeyword             = "CanonicalizeHostname"
	CanonicalizeMaxDotsKeyword              = "CanonicalizeMaxDots"
	CanonicalizePermittedCNAMEsKeyword      = "CanonicalizePermittedCNAMEs"
	ChallengeResponseAuthenticationKeyword  = "ChallengeResponseAuthentication"
	CheckHostIPKeyword                      = "CheckHostIP"
	CipherKeyword                           = "Cipher"
	CiphersKeyword                          = "Ciphers"
	ClearAllForwardingsKeyword              = "ClearAllForwardings"
	CompressionKeyword                      = "Compression"
	CompressionLevelKeyword                 = "CompressionLevel"
	ConnectionAttemptsKeyword               = "ConnectionAttempts"
	ConnectTimeoutKeyword                   = "ConnectTimeout"
	ControlMasterKeyword                    = "ControlMaster"
	ControlPathKeyword                      = "ControlPath"
	ControlPersistKeyword                   = "ControlPersist"
	DynamicForwardKeyword                   = "DynamicForward"
	EnableSSHKeysignKeyword                 = "EnableSSHKeysign"
	EscapeCharKeyword                       = "EscapeChar"
	ExitOnForwardFailureKeyword             = "ExitOnForwardFailure"
	FingerprintHashKeyword                  = "FingerprintHash"
	ForwardAgentKeyword                     = "ForwardAgent"
	ForwardX11Keyword                       = "ForwardX11"
	ForwardX11TimeoutKeyword                = "ForwardX11Timeout"
	ForwardX11TrustedKeyword                = "ForwardX11Trusted"
	GatewayPortsKeyword                     = "GatewayPorts"
	GlobalKnownHostsFileKeyword             = "GlobalKnownHostsFile"
	GSSAPIAuthenticationKeyword             = "GSSAPIAuthentication"
	GSSAPIDelegateCredentialsKeyword        = "GSSAPIDelegateCredentials"
	HashKnownHostsKeyword                   = "HashKnownHosts"
	HostbasedAuthenticationKeyword          = "HostbasedAuthentication"
	HostbasedKeyTypesKeyword                = "HostbasedKeyTypes"
	HostKeyAlgorithmsKeyword                = "HostKeyAlgorithms"
	HostKeyAliasKeyword                     = "HostKeyAlias"
	HostNameKeyword                         = "HostName"
	IdentitiesOnlyKeyword                   = "IdentitiesOnly"
	IdentityFileKeyword                     = "IdentityFile"
	IgnoreUnknownKeyword                    = "IgnoreUnknown"
	IPQoSKeyword                            = "IPQoS"
	IncludeKeyword                          = "Include"
	KbdInteractiveAuthenticationKeyword     = "KbdInteractiveAuthentication"
	KbdInteractiveDevicesKeyword            = "KbdInteractiveDevices"
	KexAlgorithmsKeyword                    = "KexAlgorithms"
	LocalCommandKeyword                     = "LocalCommand"
	LocalForwardKeyword                     = "LocalForward"
	LogLevelKeyword                         = "LogLevel"
	MACsKeyword                             = "MACs"
	NoHostAuthenticationForLocalhostKeyword = "NoHostAuthenticationForLocalhost"
	NumberOfPasswordPromptsKeyword          = "NumberOfPasswordPrompts"
	PasswordAuthenticationKeyword           = "PasswordAuthentication"
	PermitLocalCommandKeyword               = "PermitLocalCommand"
	PKCS11ProviderKeyword                   = "PKCS11Provider"
	PortKeyword                             = "Port"
	PreferredAuthenticationsKeyword         = "PreferredAuthentications"
	ProtocolKeyword                         = "Protocol"
	ProxyCommandKeyword                     = "ProxyCommand"
	ProxyUseFdpassKeyword                   = "ProxyUseFdpass"
	PubkeyAuthenticationKeyword             = "PubkeyAuthentication"
	RekeyLimitKeyword                       = "RekeyLimit"
	RemoteForwardKeyword                    = "RemoteForward"
	RequestTTYKeyword                       = "RequestTTY"
	RevokedHostKeysKeyword                  = "RevokedHostKeys"
	RhostsRSAAuthenticationKeyword          = "RhostsRSAAuthentication"
	RSAAuthenticationKeyword                = "RSAAuthentication"
	SendEnvKeyword                          = "SendEnv"
	ServerAliveCountMaxKeyword              = "ServerAliveCountMax"
	ServerAliveIntervalKeyword              = "ServerAliveInterval"
	StreamLocalBindMaskKeyword              = "StreamLocalBindMask"
	StreamLocalBindUnlinkKeyword            = "StreamLocalBindUnlink"
	StrictHostKeyCheckingKeyword            = "StrictHostKeyChecking"
	TCPKeepAliveKeyword                     = "TCPKeepAlive"
	TunnelKeyword                           = "Tunnel"
	TunnelDeviceKeyword                     = "TunnelDevice"
	UpdateHostKeysKeyword                   = "UpdateHostKeys"
	UsePrivilegedPortKeyword                = "UsePrivilegedPort"
	UserKeyword                             = "User"
	UserKnownHostsFileKeyword               = "UserKnownHostsFile"
	VerifyHostKeyDNSKeyword                 = "VerifyHostKeyDNS"
	VisualHostKeyKeyword                    = "VisualHostKey"
	XAuthLocationKeyword                    = "XAuthLocation"

	FileHeader                = "# ssh config generated by some go code (github.com/jasonmoo/ssh_config)"
	GlobalConfigurationHeader = "# global configuration"
	HostConfigurationHeader   = "# host-based configuration"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Source  []byte
	Globals []*Param
	Hosts   []*Host
}

func Parse

func Parse(r io.Reader) (*Config, error)

func (*Config) FindByHostname

func (config *Config) FindByHostname(hostname string) *Host

func (*Config) GetHost

func (config *Config) GetHost(hostname string) *Host

func (*Config) GetParam

func (config *Config) GetParam(keyword string) *Param

func (*Config) WriteTo

func (config *Config) WriteTo(w io.Writer) error

func (*Config) WriteToFilepath

func (config *Config) WriteToFilepath(file_path string) error

type Host

type Host struct {
	Comments  []string
	Hostnames []string
	Params    []*Param
}

func NewHost

func NewHost(hostnames []string, comments []string) *Host

func (*Host) GetParam

func (host *Host) GetParam(keyword string) *Param

func (*Host) String

func (host *Host) String() string

type Param

type Param struct {
	Comments []string
	Keyword  string
	Args     []string
}

func NewParam

func NewParam(keyword string, args []string, comments []string) *Param

func (*Param) String

func (param *Param) String() string

func (*Param) Value

func (param *Param) Value() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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