sshx

package
v0.2026250.1815 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 17 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainerSSHKeyDir

func ContainerSSHKeyDir(name string) (string, error)

ContainerSSHKeyDir returns the directory for storing a container's SSH keypair.

func DialSSH

func DialSSH(t spec.SSHTarget) (*ssh.Client, error)

DialSSH opens an authenticated SSH client connection to the target. Caller must Close.

func GenerateSSHKeypair

func GenerateSSHKeypair(dir string) (string, error)

GenerateSSHKeypair creates an ed25519 keypair in the given directory. Returns the public key in authorized_keys format. Idempotent: when the .pub file already exists in dir, the existing public key is read and returned without generating a new pair (so multiple VM lifecycle calls — build, create, start — use the same identity).

func ResolveSSHPubKey

func ResolveSSHPubKey(flag, generateDir string) (string, error)

ResolveSSHPubKey resolves the --ssh-key flag to a public key string. Values: "auto" (default ~/.ssh key), "none", "generate", or a file path. generateDir is the directory where generated keypairs are stored (only used for "generate").

func SSHAuthMethods

func SSHAuthMethods() ([]ssh.AuthMethod, error)

SSHAuthMethods probes the user's environment for usable SSH auth. Agent first, then the three common Ed25519/RSA/ECDSA private keys.

func SSHClientConfig

func SSHClientConfig(t spec.SSHTarget) (*ssh.ClientConfig, error)

SSHClientConfig builds an *ssh.ClientConfig for the given target using (in order):

  • SSH_AUTH_SOCK — ssh-agent keys, if available.
  • ~/.ssh/id_ed25519, ~/.ssh/id_rsa, ~/.ssh/id_ecdsa — any readable key file (unencrypted; we don't prompt for passphrases here — the user's normal workflow should keep keys in the agent).

Host-key checking honors ~/.ssh/known_hosts when present; otherwise it falls back to InsecureIgnoreHostKey. Callers that need strict verification should ensure the agent path is available.

Types

type SSHTunnel

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

SSHTunnel is a live SSH connection plus any forwards opened against it. Call Close to tear everything down.

func NewSSHTunnel

func NewSSHTunnel(t spec.SSHTarget) (*SSHTunnel, error)

NewSSHTunnel dials the target and returns a tunnel handle. The underlying ssh.Client can host any number of forwards.

func (*SSHTunnel) Client

func (t *SSHTunnel) Client() *ssh.Client

Client returns the underlying SSH client, for consumers that open their own channels over the same connection (e.g. dialing a remote unix socket). The client stays owned by the tunnel — use Close to disconnect.

func (*SSHTunnel) Close

func (t *SSHTunnel) Close() error

Close tears down all open forwards, then disconnects. Idempotent.

func (*SSHTunnel) ForwardTCP

func (t *SSHTunnel) ForwardTCP(ctx context.Context, remoteHost string, remotePort int) (string, func(), error)

ForwardTCP opens a local 127.0.0.1:<random> listener that forwards each accepted connection to <remoteHost>:<remotePort> via the SSH connection. Returns the local "127.0.0.1:<port>" address plus a cleanup func that closes the listener (but not the SSH client — use Close for that).

func (*SSHTunnel) ForwardUnix

func (t *SSHTunnel) ForwardUnix(ctx context.Context, remoteSocket string) (string, func(), error)

ForwardUnix opens a local UNIX socket under /tmp/charly-tunnel-<uuid>.sock that forwards each accepted connection to <remoteSocket> on the other side of the SSH connection. Returns the local socket path plus a cleanup func.

Jump to

Keyboard shortcuts

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