sshclient

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Overview

Package sshclient provides SSH client dialing, SFTP, tunnels, and known_hosts helpers for honey.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DialSSHClient

func DialSSHClient(userOverride, hostAlias string, overridePort int, recipeIdentityFile string) (*ssh.Client, func(), error)

DialSSHClient returns the leaf *ssh.Client and a cleanup that closes the full ProxyJump chain.

func RunTunnelGo

func RunTunnelGo(ctx context.Context, user, host string, sshPort int, localFwd string, out io.Writer) error

RunTunnelGo listens on 127.0.0.1:<localPort> and forwards to remoteHost:remotePort via the SSH server (host). sshPort is 0 to use ~/.ssh/config Port / default 22 only, or 1..65535 to override the leaf SSH server port.

func StartPTYResizeForwarding

func StartPTYResizeForwarding(fd int, sess *ssh.Session, onResize func(cols, rows int)) (stop func())

StartPTYResizeForwarding sends SIGWINCH-driven size updates to the remote PTY.

func StartTerminalResize

func StartTerminalResize(fd int, onSize func(cols, rows int)) (stop func())

StartTerminalResize invokes onSize(cols, rows) whenever the terminal receives SIGWINCH.

Types

type HoneyClient

type HoneyClient struct {
	*goph.Client
	// contains filtered or unexported fields
}

HoneyClient wraps goph.Client so Close() also shuts down ProxyJump bastion clients.

func DialHoneyClient

func DialHoneyClient(userOverride, hostAlias string, overridePort int, recipeIdentityFile string) (*HoneyClient, error)

DialHoneyClient opens SSH using ~/.ssh/config (User, HostName, Port, IdentityFile, ProxyJump, StrictHostKeyChecking, UserKnownHostsFile, GlobalKnownHostsFile) and known_hosts verification via golang.org/x/crypto/ssh/knownhosts (see hostKeyCallbackForHostSSH). When system OpenSSH is available, resolution uses `ssh -G` so Match blocks apply; set HONEY_SSH_OPENSSH_G=0 to disable. Auth also uses HONEY_SSH_IDENTITY_FILES and default ~/.ssh key names (see buildAuthWithIdentityFiles). If overridePort is in 1..65535, it replaces the leaf port from resolution (e.g. from record meta.ssh_port). When recipeIdentityFile is non-empty, auth uses only that private key (see buildAuthExclusiveIdentityFile).

func (*HoneyClient) Close

func (h *HoneyClient) Close() error

Close closes the target session transport, then any bastion SSH clients (reverse order).

func (*HoneyClient) Download

func (h *HoneyClient) Download(remotePath, localPath string) error

Download copies a remote file to a local path over SFTP.

func (*HoneyClient) LeafSSH

func (h *HoneyClient) LeafSSH() *ssh.Client

LeafSSH returns the leaf *ssh.Client used for sessions/SFTP on the target host (ProxyJump hops are parents).

func (*HoneyClient) ListRemoteDir

func (h *HoneyClient) ListRemoteDir(path string) ([]hostexec.RemoteFileEntry, error)

ListRemoteDir returns sorted directory entries for the given remote path.

func (*HoneyClient) MkdirAllRemote

func (h *HoneyClient) MkdirAllRemote(path string) error

MkdirAllRemote creates a remote directory tree via SFTP.

func (*HoneyClient) RemoveRemote

func (h *HoneyClient) RemoveRemote(path string, recursive bool) error

RemoveRemote deletes a remote file or directory (recursive walks children first).

func (*HoneyClient) RunWithStreams

func (h *HoneyClient) RunWithStreams(cmd string, stdin io.Reader, stdout, stderr io.Writer) error

RunWithStreams runs cmd on the remote (non-interactive session) with stdin/stdout/stderr attached. stderr may be nil to discard remote stderr.

func (*HoneyClient) StatRemote

func (h *HoneyClient) StatRemote(path string) (hostexec.RemoteFileEntry, error)

StatRemote returns metadata for a single remote filesystem object.

func (*HoneyClient) Upload

func (h *HoneyClient) Upload(localPath, remotePath string) error

Upload copies a local file to the remote path over SFTP.

func (*HoneyClient) UploadWithProgress

func (h *HoneyClient) UploadWithProgress(localPath, remotePath string, onProgress func(written, total int64)) error

UploadWithProgress copies a local file to the remote path over SFTP, calling onProgress with cumulative bytes written to the remote and the local file size (throttled). onProgress may be nil.

Jump to

Keyboard shortcuts

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