secureshell: maze.io/x/secureshell Index | Files | Directories

package secureshell

import "maze.io/x/secureshell"

Index

Package Files

auth.go auth_posix.go client.go compat.go conn.go server.go session.go tunnel.go

Constants

const (
    ChannelTypeSession        = "session"
    ChannelTypeDirectTCPIP    = "direct-tcpip"
    ChannelTypeForwardedTCPIP = "forwarded-tcpip"
)

SSH channel types.

const (
    RequestTypeTCPIPForward       = "tcpip-forward"
    RequestTypeCancelTCPIPForward = "cancel-tcpip-forward"
    RequestTypeKeepalive          = "keepalive@openssh.com"
)

SSH request types.

Variables

var DefaultServerChannelHandlers = map[string]ServerChannelHandler{
    ChannelTypeSession:     DefaultSessionHandler,
    ChannelTypeDirectTCPIP: DirectTCPIPHandler,
}
var DefaultServerRequestHandlers = map[string]ServerRequestHandler{
    RequestTypeTCPIPForward:       ForwardedTCPIPHandler,
    RequestTypeCancelTCPIPForward: ForwardedTCPIPHandler,
    RequestTypeKeepalive:          StaticRequestHandler(true, nil),
}

DefaultServerRequestHandlers are the defaults for an unconfigured Server.

var DefaultVersion = "Go"

DefaultVersion is the default SSH version identifier, if none has been configured.

var ErrNoConfig = errors.New("secureshell: config can't be nil")

ErrNoConfig is returned if the caller passed a nil config.

func ClientAuth Uses

func ClientAuth(config *ssh.ClientConfig) (io.Closer, error)

ClientAuth configures the SSH client configuration authentication based on the environment. The returned closer should be closed when no more authentication is required.

func ClientAuthCallback Uses

func ClientAuthCallback(config *ssh.ClientConfig, prompt func() (secret string, err error)) (io.Closer, error)

ClientAuthCallback configures the SSH client configuration authentication based on the environment, with the supplied password callback function. The returned closer should be closed when no more authentication is required.

func DefaultSessionHandler Uses

func DefaultSessionHandler(server *Server, conn *ssh.ServerConn, newChannel ssh.NewChannel) error

DefaultSessionHandler accepts the session channel and starts handling requests from the channel. The default handler will block until the session has finished.

func DirectTCPIPHandler Uses

func DirectTCPIPHandler(server *Server, conn *ssh.ServerConn, newChannel ssh.NewChannel) error

DirectTCPIPHandler is a server channel handler for TCP/IP forwarding channels. See RFC4254 7.2. TCP/IP Forwarding Channels

func ForwardedTCPIPHandler Uses

func ForwardedTCPIPHandler(server *Server, conn *ssh.ServerConn, request *ssh.Request) (ok bool, payload []byte)

ForwardedTCPIPHandler is a server channel handler for port forwarding. See RFC4254 7.1. Requesting Port Forwarding

func NewSession Uses

func NewSession(server *Server, conn *ssh.ServerConn, channel ssh.Channel) *session

NewSession returns a default session.

type AuthMethod Uses

type AuthMethod = ssh.AuthMethod

Type aliases with the Go ssh package. They exist for convenience, but also to allow godoc to align functions and their return types properly.

func AuthAgent Uses

func AuthAgent() (AuthMethod, io.Closer, error)

AuthAgent connects to the default OpenSSH agent socket and adds it to the configuration as authentication method.

func AuthAgentSock Uses

func AuthAgentSock(name string) (AuthMethod, io.Closer, error)

AuthAgentSock connects to the specified OpenSSH agent socket and adds it to the configuration as authentication method.

func AuthPassword Uses

func AuthPassword() AuthMethod

AuthPassword prompts the user for a password on standard input.

type Channel Uses

type Channel = ssh.Channel

Type aliases with the Go ssh package. They exist for convenience, but also to allow godoc to align functions and their return types properly.

type Client Uses

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

func NewClient Uses

func NewClient(network, address string, config *ssh.ClientConfig) (*Client, error)

func NewClientConn Uses

func NewClientConn(nc net.Conn, address string, config *ssh.ClientConfig) (*Client, error)

func (*Client) Close Uses

func (c *Client) Close() error

func (*Client) Command Uses

func (c *Client) Command(name string, arg ...string) (*ClientSession, error)

func (*Client) NewSession Uses

func (c *Client) NewSession() (*ClientSession, error)

type ClientDialer Uses

type ClientDialer interface {
    // Dial connects to the address on the named network.
    Dial(network, address string) (net.Conn, error)

    // DialContext connects to the address on the named network using the provided context.
    DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

type ClientSession Uses

type ClientSession struct {
    *ssh.Session
}

type HostKeyCallback Uses

type HostKeyCallback = ssh.HostKeyCallback

Type aliases with the Go ssh package. They exist for convenience, but also to allow godoc to align functions and their return types properly.

func KnownHosts Uses

func KnownHosts(files ...string) (HostKeyCallback, error)

KnownHosts creates a host key callback from the given OpenSSH host key files. By preference, the key check operates on the hostname if available, i.e. if a server changes its IP address, the host key check will still succeed, even though a record of the new IP address is not available. If no files are specified, the default known hosts file for the current user will be used.

type PseudoTerminal Uses

type PseudoTerminal struct {
    // Type is the TERM environment variable (e.g. "vt100").
    Type string

    // Width is the width in characters.
    Width uint32

    // Height is the height in characters.
    Height uint32

    // PixelWidth is the width in pixels.
    PixelWidth uint32

    // PixelHeight is the height in pixels.
    PixelHeight uint32

    // RawModes are the encoded terminal modes.
    RawModes string
}

PseudoTerminal describes the specification for an SSH connected pseudo terminal.

func (PseudoTerminal) Modes Uses

func (pty PseudoTerminal) Modes() ssh.TerminalModes

Modes parses the RawModes.

type PublicKey Uses

type PublicKey = ssh.PublicKey

Type aliases with the Go ssh package. They exist for convenience, but also to allow godoc to align functions and their return types properly.

type Server Uses

type Server struct {
    // Config is the (template) server configuration.
    // Setting this property is required and it should at least include any of
    // PasswordCallback, PublicKeyCallback, KeyboardInteractiveCallback or NoClientAuth.
    //
    // The value of ServerVersion from the Config is ignored, see Version below.
    Config *ssh.ServerConfig `toml:"config" json:"config"`

    // Addr is the listen address.
    Addr string `json:"addr" toml:"addr"`

    // Keys are the host keys.
    Keys []ssh.Signer `hcl:"-" json:"-" mapstructure:"-" toml:"-" yaml:"-"`

    // KeyFiles are the host key files (optional).
    KeyFiles []string `hcl:"keys" json:"keys" mapstructure:"keys" toml:"keys" yaml:"keys"`

    // KeepaliveInterval is the delay between server initiated keepalive requests.
    KeepaliveInterval time.Duration `hcl:"keepalive" json:"keepalive" mapstructure:"keepalive" toml:"keepalive" yaml:"keepalive"`

    // Version of this server.
    // If no Version is specified, DefaultVersion will be used.
    // Contrary to the ServerVersion in config.ServerConfig, this version does not
    // require the caller to prepend "SSH-2.0-".
    Version string `json:"version" toml:"version"`

    // Banner, if present, is sent to the client after key exchange completed but before authentication.
    // If the Config has a BannerCallback set, it takes precedence over this setting.
    Banner string `json:"banner" toml:"banner"`

    // AcceptCallback is called after accepting a new connection.
    AcceptCallback func(net.Conn) error `hcl:"-" json:"-" mapstructure:"-" toml:"-" yaml:"-"`

    // ConnectCallback is called after accepting a new SSH client.
    ConnectCallback func(ssh.Conn) error `hcl:"-" json:"-" mapstructure:"-" toml:"-" yaml:"-"`

    // DisconnectCallback is called when a connected SSH client connection is lost.
    DisconnectCallback func(ssh.Conn, error) `hcl:"-" json:"-" mapstructure:"-" toml:"-" yaml:"-"`

    // ChannelHandler are the SSH channel handlers.
    //
    // A default handler may be specified with "default".
    ChannelHandler map[string]ServerChannelHandler `hcl:"-" json:"-" mapstructure:"-" toml:"-" yaml:"-"`

    // RequestHandler are the SSH request handlers.
    //
    // A default handler may be specified with "default".
    RequestHandler map[string]ServerRequestHandler `hcl:"-" json:"-" mapstructure:"-" toml:"-" yaml:"-"`

    // SessionHandler is called if a new client session is opened.
    //
    // This handler is used by the DefaultSessionHandler, if it is installed in the
    // RequestHandler map to handle "session" requests.
    SessionHandler func(Session) `hcl:"-" json:"-" mapstructure:"-" toml:"-" yaml:"-"`

    // TunnelHandler is used to establish outbound TCP/IP tunnels.
    // If the callback is not set, tunneling requests will be refused.
    TunnelHandler func(conn ssh.Conn, address string) (net.Conn, error) `hcl:"-" json:"-" mapstructure:"-" toml:"-" yaml:"-"`

    // ReverseTunnelHandler is used to establish reverse TCP/IP tunnels.
    // If the callback is not set, tunneling requests will be refused.
    ReverseTunnelHandler func(conn ssh.Conn, localAddress, remoteAddress string) (net.Listener, error) `hcl:"-" json:"-" mapstructure:"-" toml:"-" yaml:"-"`
    // contains filtered or unexported fields
}

Server are the settings for running an SSH server. Implementations are expected to provide at least a Config, see the Config field for more details.

func (*Server) Close Uses

func (s *Server) Close() error

func (*Server) Handshake Uses

func (s *Server) Handshake(nc net.Conn, config *ssh.ServerConfig) error

Handshake performs an SSH server handshake with the provided connection.

func (*Server) ListenAndServe Uses

func (s *Server) ListenAndServe() error

func (*Server) Serve Uses

func (s *Server) Serve(l net.Listener) error

type ServerChannelHandler Uses

type ServerChannelHandler func(*Server, *ssh.ServerConn, ssh.NewChannel) error

ServerChannelHandler is a callback for new client channels.

type ServerRequestHandler Uses

type ServerRequestHandler func(*Server, *ssh.ServerConn, *ssh.Request) (ok bool, payload []byte)

ServerRequestHandler is a callback for client requests.

func StaticRequestHandler Uses

func StaticRequestHandler(ok bool, payload []byte) ServerRequestHandler

StaticRequestHandler send a static reply.

type Session Uses

type Session interface {
    // Channel is the underlying transport channel.
    // It provides an io.ReadWriteCloser interface.
    ssh.Channel

    // ConnMetadata holds metadata for the connection.
    ssh.ConnMetadata

    // HandleRequest adds a request handler callback.
    // The handler is ignored if the callback is nil.
    // If the requestType is overlapping with a builtin handler, the builtin
    // handler will stop working.
    // If the handler returns an error, the client connection will be terminated.
    HandleRequest(requestType string, callback SessionRequestHandler)

    // HandleRequests consumes and handles new requests from the passed channel.
    HandleRequests(requests <-chan *ssh.Request) error

    // Args are the arguments supplied to the session.
    Args() []string

    // Getenv retrieves the value of the environment variable named by the key.
    // It returns the value, which will be empty if the variable is not present.
    // To distinguish between an empty value and an unset value, use LookupEnv.
    Getenv(key string) string

    // LookupEnv retrieves the value of the environment variable named by the key.
    // If the variable is present in the environment the value (which may be empty) is returned and the boolean is true.
    // Otherwise the returned value will be empty and the boolean will be false.
    LookupEnv(key string) (string, bool)

    // Setenv sets the value of the environment variable named by the key.
    Setenv(key, value string)

    // Environ returns the environment as key-value map.
    Environ() map[string]string

    // Permissions returned after authenticating the client connection.
    Permissions() *ssh.Permissions

    // PseudoTerminal returns information about the connected pseudo terminal.
    // Also, a channel is returned that will receive window change events.
    // The boolean indicates whether the connected client has requested a pseudo terminal or not.
    PseudoTerminal() (PseudoTerminal, <-chan WindowChange, bool)

    // Exit sends an exit status and then closes the session.
    Exit(code int) error
}

type SessionRequestHandler Uses

type SessionRequestHandler func(Session, *ssh.Request) error

SessionRequestHandler is a callback for session requests.

type WindowChange Uses

type WindowChange struct {
    // Width is the width in characters.
    Width uint32

    // Height is the height in characters.
    Height uint32

    // PixelWidth is the width in pixels.
    PixelWidth uint32

    // PixelHeight is the height in pixels.
    PixelHeight uint32
}

WindowChange describes the window change for a connected pseudo terminal.

func (WindowChange) String Uses

func (change WindowChange) String() string

Directories

PathSynopsis
scpPackage scp implements the Secure Copy (SCP) client protocol.

Package secureshell imports 20 packages (graph) and is imported by 1 packages. Updated 2019-09-21. Refresh now. Tools for package owners.