Documentation ¶
Index ¶
- Constants
- Variables
- func ClientAuth(config *ssh.ClientConfig) (io.Closer, error)
- func ClientAuthCallback(config *ssh.ClientConfig, prompt func() (secret string, err error)) (io.Closer, error)
- func DefaultSessionHandler(server *Server, conn *ssh.ServerConn, newChannel ssh.NewChannel) error
- func DirectTCPIPHandler(server *Server, conn *ssh.ServerConn, newChannel ssh.NewChannel) error
- func ForwardedTCPIPHandler(server *Server, conn *ssh.ServerConn, request *ssh.Request) (ok bool, payload []byte)
- func NewSession(server *Server, conn *ssh.ServerConn, channel ssh.Channel) *session
- type AuthMethod
- type Channel
- type Client
- type ClientDialer
- type ClientSession
- type HostKeyCallback
- type PseudoTerminal
- type PublicKey
- type Server
- type ServerChannelHandler
- type ServerRequestHandler
- type Session
- type SessionRequestHandler
- type WindowChange
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.
ErrNoConfig is returned if the caller passed a nil config.
Functions ¶
func ClientAuth ¶
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 ¶
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 ¶
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 ¶ added in v1.0.3
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
Types ¶
type AuthMethod ¶
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 ¶
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 ¶
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 ¶
func AuthPassword() AuthMethod
AuthPassword prompts the user for a password on standard input.
type 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 ¶
func NewClientConn ¶
func (*Client) Command ¶
func (c *Client) Command(name string, arg ...string) (*ClientSession, error)
func (*Client) NewSession ¶
func (c *Client) NewSession() (*ClientSession, error)
type ClientDialer ¶
type HostKeyCallback ¶
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 ¶
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 ¶
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 ¶
func (pty PseudoTerminal) Modes() ssh.TerminalModes
Modes parses the RawModes.
type 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 ¶
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) Handshake ¶ added in v1.0.4
Handshake performs an SSH server handshake with the provided connection.
type ServerChannelHandler ¶
type ServerChannelHandler func(*Server, *ssh.ServerConn, ssh.NewChannel) error
ServerChannelHandler is a callback for new client channels.
type ServerRequestHandler ¶
ServerRequestHandler is a callback for client requests.
func StaticRequestHandler ¶ added in v1.0.3
func StaticRequestHandler(ok bool, payload []byte) ServerRequestHandler
StaticRequestHandler send a static reply.
type Session ¶
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 ¶ added in v1.0.7
SessionRequestHandler is a callback for session requests.
type WindowChange ¶
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 ¶ added in v1.0.2
func (change WindowChange) String() string