Documentation ¶
Index ¶
- Constants
- type Auth
- type Config
- type Handler
- type HandlerFactory
- type HostKeyResolver
- type Shell
- func (s *Shell) Add(b byte) error
- func (s *Shell) AddString(val string) error
- func (s *Shell) Bell() error
- func (s *Shell) InstanceName() string
- func (s *Shell) OutputLine(line string) error
- func (s *Shell) Read() (string, error)
- func (s *Shell) Refresh() error
- func (s *Shell) SetPrompt(prompt string)
- type SshServer
- type User
Examples ¶
Constants ¶
View Source
const ( DefaultConfigHistorySize = 100 DefaultBind = ":22" )
View Source
const ( ETX = 0x3 // control-C EOT = 0x4 // control-D BEL = 0x7 BS = 0x8 LF = 0xa CR = 0xd ESC = 0x1b CSI = '[' DEL = 0x7f )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler interface { // HandleLine is called with the next line that was consumed by the SSH shell. Typically this // is due the user typing a command string. // If an error is returned, then the error is reported back to the SSH client and the SSH // session is closed. HandleLine(line string) error // HandleEof is called when the user types Control-D // If an error is returned, then the error is reported back to the SSH client and the SSH // session is closed. HandleEof() error }
type HandlerFactory ¶
type HostKeyResolver ¶
type HostKeyResolver struct {
// contains filtered or unexported fields
}
func NewHostKeyResolver ¶
func NewHostKeyResolver(config *Config) *HostKeyResolver
func (*HostKeyResolver) Resolve ¶
func (r *HostKeyResolver) Resolve() string
func (*HostKeyResolver) ResolveOption ¶
func (r *HostKeyResolver) ResolveOption() ssh.Option
type Shell ¶
type Shell struct {
// contains filtered or unexported fields
}
func (*Shell) InstanceName ¶
func (*Shell) OutputLine ¶
type SshServer ¶
type SshServer struct { *Config HandlerFactory }
SshServer manages acceptance of and authenticating SSH connections and delegating input to a Handler for each session instantiated by the given HandlerFactory. The zero value of this struct will use reasonable defaults, but won't be very useful since the default handler just outputs remote inputs to logs.
func (*SshServer) ListenAndServe ¶
ListenAndServe will block listening for new SSH connections and serving those with a new instance of Shell and a Handler each.
Example ¶
package main import ( shell "github.com/itzg/go-ssh-shell" "log" ) type exampleHandler struct { s shell.Shell } func exampleHandlerFactory(s *shell.Shell) shell.Handler { return &exampleHandler{} } func (h *exampleHandler) HandleLine(line string) error { log.Printf("LINE from %s: %s", h.s.InstanceName(), line) return nil } func (h *exampleHandler) HandleEof() error { log.Printf("EOF from %s", h.s.InstanceName()) return nil } func main() { sshServer := &shell.SshServer{ Config: &shell.Config{ Bind: ":2222", Users: map[string]shell.User{ "user": {Password: "notsecure"}, }, }, HandlerFactory: exampleHandlerFactory, } log.Fatal(sshServer.ListenAndServe()) }
Output:
Click to show internal directories.
Click to hide internal directories.