sshserver

package
v0.0.0-...-979150d Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package sshserver provides the shared SSH transport, SFTP, and loopback forwarding used by userland and service hosts. Shell execution belongs to the embedding host; this package contains no interpreter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthorizedKeyAllowed

func AuthorizedKeyAllowed(name string, offered ssh.PublicKey) bool

AuthorizedKeyAllowed reloads the file for every authentication. This makes removal take effect immediately and keeps the key material out of process state and logs.

func ListenAndServe

func ListenAndServe(ctx context.Context, address string, cfg Config) error

ListenAndServe accepts host:port or a bare port, and owns its listener.

func Serve

func Serve(ctx context.Context, ln net.Listener, cfg Config) error

Serve accepts connections until cancellation or listener failure. It owns the listener and all accepted connections, including incomplete handshakes.

func ServeConn

func ServeConn(ctx context.Context, conn net.Conn, config *ssh.ServerConfig, handlers Handlers) error

ServeConn performs a handshake and routes channels until the connection ends. It owns conn. All callbacks receive a context canceled on disconnect.

Types

type Config

type Config struct {
	AuthorizedKeysPath string
	HostKey            ssh.Signer
	// Execute runs a command using the embedding host's shell. A nil callback
	// disables exec; SFTP and loopback forwarding remain available.
	Execute func(context.Context, string, io.Reader, io.Writer, io.Writer) uint32
}

Config supplies a standalone key-authenticated SSH listener. Only the current OS user can authenticate. AuthorizedKeysPath defaults to ~/.ssh/authorized_keys.

type Handlers

type Handlers struct {
	AllowRemoteForward bool
	Session            func(context.Context, *ssh.ServerConn, ssh.Channel, <-chan *ssh.Request)
	Channel            func(context.Context, ssh.NewChannel)
}

Handlers lets service hosts reuse the SSH connection and forwarding lifecycle with their existing authentication, session, and destination policies.

Jump to

Keyboard shortcuts

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