项目作者: itzg

项目描述 :
Go module that serves SSH sessions with an interactive shell
高级语言: Go
项目地址: git://github.com/itzg/go-ssh-shell.git
创建时间: 2019-09-19T21:23:24Z
项目社区:https://github.com/itzg/go-ssh-shell

开源协议:MIT License

下载


Go module that serves SSH sessions with an interactive shell. The interactive shell includes support for command history, which can be recalled using the up/down arrow keys.

Adding module

  1. go get -u github.com/itzg/go-ssh-shell

Example

  1. package main
  2. import (
  3. shell "github.com/itzg/go-ssh-shell"
  4. "log"
  5. )
  6. type exampleHandler struct {
  7. s shell.Shell
  8. }
  9. func exampleHandlerFactory(s *shell.Shell) shell.Handler {
  10. return &exampleHandler{}
  11. }
  12. func (h *exampleHandler) HandleLine(line string) error {
  13. log.Printf("LINE from %s: %s", h.s.InstanceName(), line)
  14. return nil
  15. }
  16. func (h *exampleHandler) HandleEof() error {
  17. log.Printf("EOF from %s", h.s.InstanceName())
  18. return nil
  19. }
  20. func main() {
  21. sshServer := &shell.SshServer{
  22. Config: &shell.Config{
  23. Bind: ":2222",
  24. Users: map[string]shell.User{
  25. "user": {Password: "notsecure"},
  26. },
  27. },
  28. HandlerFactory: exampleHandlerFactory,
  29. }
  30. log.Fatal(sshServer.ListenAndServe())
  31. }