ssh_client

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 11 Imported by: 0

README

ssh_client

Go ssh client configured from openssh config files

Go code example

	host, err := ssh_client.New("ProxyChainHost", ssh_client.DefaultUserSettings)
	if err != nil {
		log.Fatalln(err)
	}

	conn, err := host.Dial("tcp")
	if err != nil {
		log.Fatalln(err)
	}
	defer conn.Close()

	// From here we can use `conn` to Dial remote ports and/or open a session.

Corresponding ~/.ssh/config example

Host ProxyChainHost
	Hostname FinalHostname
	ProxyJump %r@FirstProxy,ConfiguredProxy

Host ConfiguredProxy
	Hostname intnames.dedibox.vdg.name
	User root

Notes

  • The keys required for all hosts must be loaded in ssh-agent before connection. (loading keys is not supported).
  • Entries in known_hosts must be present (Adding entries is not supported).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAgentDisabled = errors.New("SSH Agent Disabled")

Functions

func ExpandHome

func ExpandHome(inputPath string) string

func MultipleDefault

func MultipleDefault(key string) []string

MultipleDefault returns the default values for the given keyword, for example// {"22"} if the keyword is "Port". MultipleDefault returns nil if the keyword has no default, or if the keyword is unknown. Keyword matching is case-insensitive.

MultipleDefault return more than one element for "IdentityFile" keyword.

Types

type Host

type Host struct {
	Name     string
	Hostname string
	Port     string
	User     string

	*ssh.ClientConfig
	// contains filtered or unexported fields
}

func New

func New(uri string, cfg sshSettingsGetter) (*Host, error)

func ParseSshURI

func ParseSshURI(uri string) *Host

ParseSshURI parse either [user@]host[:port] or an ssh URI ie ssh://[user@]host[:port].

func (*Host) Addr

func (h *Host) Addr() string

func (*Host) Agent

func (h *Host) Agent() (agent.ExtendedAgent, error)

TODO once or cache

func (*Host) AgentSockName

func (h *Host) AgentSockName() string

func (*Host) ConfigGet

func (h *Host) ConfigGet(key string) string

func (*Host) ConfigGetAll

func (h *Host) ConfigGetAll(key string) []string

func (*Host) Configure

func (h *Host) Configure(cfg sshSettingsGetter) error

func (*Host) Dial

func (h *Host) Dial(network string) (*ssh.Client, error)

func (*Host) ExpandTokens

func (h *Host) ExpandTokens(in string) string

ExpandTokens expand % tokens

%% A literal ‘%’. %h The remote hostname. %n The original remote hostname, as given on the command line. %p The remote port. %r The remote username.

TODO: complete the list of tokens and allow selecting them depending on the key see: https://github.com/openssh/openssh-portable/blob/master/sshconnect.h#L54 %c see https://github.com/openssh/openssh-portable/blob/master/readconf.c#L354

func (*Host) GetClientConfig

func (h *Host) GetClientConfig() (*ssh.ClientConfig, error)

TODO: add options to customize config TODO: make thread safe ?

func (*Host) GetSigners

func (h *Host) GetSigners() ([]ssh.Signer, error)

func (*Host) GetSignersCallback

func (h *Host) GetSignersCallback() (func() ([]ssh.Signer, error), error)

func (*Host) IdentitiesOnly

func (h *Host) IdentitiesOnly() bool

func (*Host) IdentityPublicKeys

func (h *Host) IdentityPublicKeys() []ssh.PublicKey

func (*Host) KnownHosts

func (h *Host) KnownHosts() []string

func (*Host) NewClient

func (h *Host) NewClient(conn net.Conn) (*ssh.Client, error)

func (*Host) ProxyJump

func (h *Host) ProxyJump() []string

func (*Host) ProxyJumpHosts

func (h *Host) ProxyJumpHosts() ([]*Host, error)

type Settings

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

func OpenSSHConfig

func OpenSSHConfig(filename string) (*Settings, error)

func (*Settings) Get

func (s *Settings) Get(alias, key string) string

func (*Settings) GetAll

func (s *Settings) GetAll(alias, key string) []string

func (*Settings) GetAllStrict

func (s *Settings) GetAllStrict(alias, key string) ([]string, error)

func (*Settings) GetStrict

func (s *Settings) GetStrict(alias, key string) (string, error)

type UserSettings

type UserSettings struct {
	*ssh_config.UserSettings
}

UserSettings overrides ssh_config.UserSettings to handle MultipleDefault

func (*UserSettings) GetAll

func (u *UserSettings) GetAll(alias, key string) []string

func (*UserSettings) GetAllStrict

func (u *UserSettings) GetAllStrict(alias, key string) ([]string, error)

Jump to

Keyboard shortcuts

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