ssh

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSSHPort

func CheckSSHPort(host string, port int, timeout time.Duration) bool

func DownloadFile

func DownloadFile(client *ssh.Client, remotePath, localFile string, progress ProgressDisplayer) error

func ExecCommand added in v0.3.0

func ExecCommand(client *ssh.Client, command string) ([]byte, error)

func ExecuteSSHShell

func ExecuteSSHShell(cfg SSHConfig) error

func GetDefaultPrivateKeys added in v0.2.0

func GetDefaultPrivateKeys() []cssh.AuthMethod

func InitMultiClients added in v0.3.3

func InitMultiClients(selectedConfigs []SSHConfig) ([]*cssh.Client, error)

func LoadIdentifyFile

func LoadIdentifyFile(privateKeyPath string) (cssh.Signer, error)

func LoadSCPHistory added in v0.2.0

func LoadSCPHistory(path string) error

func NormalizeLocalAddr added in v0.6.0

func NormalizeLocalAddr(addr string) string

NormalizeLocalAddr turns "8080" into "127.0.0.1:8080" and leaves "host:port" untouched.

func NormalizeRemoteAddr added in v0.6.0

func NormalizeRemoteAddr(addr string) string

NormalizeRemoteAddr turns "80" into "localhost:80" and leaves "host:port" untouched.

func PutExecEntry added in v0.3.0

func PutExecEntry(host string, entry ExecHistoryEntry)

func PutSCPDownloadEntry added in v0.2.0

func PutSCPDownloadEntry(host string, entry SCPHistoryEntry)

func PutSCPUploadEntry added in v0.2.0

func PutSCPUploadEntry(host string, entry SCPHistoryEntry)

func SSHClient

func SSHClient(cfg SSHConfig) (*cssh.Client, error)

func UploadFile

func UploadFile(client *ssh.Client, localFile, remotePath string, progress ProgressDisplayer) error

Types

type ExecHistoryEntry added in v0.3.0

type ExecHistoryEntry struct {
	Command string
}

func GetExecEntry added in v0.3.0

func GetExecEntry(host string) ExecHistoryEntry

type Forward added in v0.6.0

type Forward struct {
	Local  string `json:"local"`
	Remote string `json:"remote"`
}

Forward is a saved local port forward, with both sides normalized.

func NewForward added in v0.6.0

func NewForward(local, remote string) Forward

func ParseLFlag added in v0.6.0

func ParseLFlag(s string) (Forward, error)

ParseLFlag parses ssh -L syntax: "[bind:]port:host:hostport", or a lone "port" for the same port on the remote host's localhost.

func ParseLocalForward added in v0.6.0

func ParseLocalForward(value string) (Forward, bool)

ParseLocalForward parses the value of an ssh_config LocalForward line: "[bind_address:]port host:hostport".

func (Forward) ConfigValue added in v0.6.0

func (f Forward) ConfigValue() string

ConfigValue renders f as an ssh_config LocalForward value, omitting the default 127.0.0.1 bind address like OpenSSH users usually write it.

func (Forward) LFlag added in v0.6.0

func (f Forward) LFlag() string

LFlag renders f in ssh -L syntax, the inverse of ParseLFlag.

func (Forward) String added in v0.6.0

func (f Forward) String() string

type HostHistoryEntry added in v0.3.0

type HostHistoryEntry struct {
	SCPHistoryEntry
	ExecHistoryEntry
}

type PortForward added in v0.6.0

type PortForward struct {
	Host   string
	Local  string // actual listening address
	Remote string
	Spec   Forward // what was asked for, as saved in config
	// contains filtered or unexported fields
}

PortForward is a local (-L style) port forward: connections accepted on Local are tunneled through the SSH host and dialed to Remote from there. It stays open until Close is called, reconnecting the SSH client if the connection drops.

func StartPortForward added in v0.6.0

func StartPortForward(cfg SSHConfig, spec Forward) (*PortForward, error)

func (*PortForward) ActiveConns added in v0.6.0

func (f *PortForward) ActiveConns() int64

ActiveConns is the number of currently tunneled connections.

func (*PortForward) Close added in v0.6.0

func (f *PortForward) Close() error

func (*PortForward) String added in v0.6.0

func (f *PortForward) String() string

type ProgressDisplayer added in v0.4.1

type ProgressDisplayer interface {
	SetTotalSize(int64)
	io.Writer
}

type SCPHistoryEntry added in v0.2.0

type SCPHistoryEntry struct {
	From string
	To   string
}

func GetSCPDownloadEntry added in v0.2.0

func GetSCPDownloadEntry(host string) SCPHistoryEntry

func GetSCPUploadEntry added in v0.2.0

func GetSCPUploadEntry(host string) SCPHistoryEntry

type SSHConfig

type SSHConfig struct {
	Host         string
	User         string
	Port         string
	HostName     string
	IdentityFile string
	Password     string
	// Managed hosts exist only in s1h's credentials file (added by older
	// versions); they move to ~/.ssh/config when edited.
	Managed bool
	// CredsEndpoint is set when HostName/User/Port come from the credentials
	// file, overriding ~/.ssh/config.
	CredsEndpoint bool
	// LocalForwards are the saved port forwards (LocalForward lines).
	LocalForwards []Forward
}

func ParseSSHConfig

func ParseSSHConfig(filePath string) ([]SSHConfig, error)

func (SSHConfig) Endpoint

func (c SSHConfig) Endpoint() string

Jump to

Keyboard shortcuts

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