gosshd

package module
v0.0.0-...-c89b3a3 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: Apache-2.0 Imports: 8 Imported by: 2

README

Go-SSHD

gosshd 是对 golang.org/x/crypto/ssh 的进一步封装,旨在快速搭建一个高度自定义的 SSH 服务器,应用于不同场景。

共分为两个包:gosshd 以及 utils,前者是对 ssh 包的进一步封装以及类型的定义;后者包含了一系列的默认实现、工具函数。

:使用 utils 包的 SimpleServerOnUnix 函数创建一个 SSHServer 实例,并监听 2222 端口

package main

import (
	"github.com/nishoushun/gosshd/utils"
	"log"
)

func main() {
	server, _ := utils.SimpleServerOnUnix()
	log.Fatalln(server.ListenAndServe(":2222"))
}

编译并运行,使用 Open-SSH 作为客户端进行连接:

image-20220505002235784

安装
go get github.com/nishoushun/gosshd
go get github.com/nishoushun/gosshd/utils
配置 SSHServer
身份认证

GoSSHD 提供了 3 种类型的身份验证方式,通过设置回调函数来规定验证过程。

utils 包中额外准备了一些身份验证回调函数类型的实现,以及一些其他的身份校验相关的工具函数。

如果希望使用 ssh 包提供的身份验证回调函数,则需要通过 SSHServerServerConfig 字段去设置相应的回调函数;否则应该通过 SSHServerSetXXX 方法设置相应的身份验证回调函数。

对于 KeyboardInteractiveChallengeCallback 类型身份认证方式实际上并不常用,该类型用于交互式问答,通过向客户端提供多个问题,然后检查客户端的回答,来决定是否通过认证。

:为 SSHServer 设置 KeyboardInteractiveChallengeCallback

import (
	"github.com/nishoushun/gosshd"
	"github.com/nishoushun/gosshd/serv"
	"log"
)

func main() {
	server, _ := utils.SimpleServerOnUnix()
	server.SetKeyboardInteractiveChallengeCallback(
		func(conn gosshd.ConnMetadata,
			client gosshd.KeyboardInteractiveChallenge) (*gosshd.Permissions, error) {
			questions := []string{
				"Hey buddy, What about the melon price? \r\n>>",
				"Is the peel made by gold or the pith made by gold? \n>>",
				"pick one for me. \n>>"}
			echo := []bool{true, true, true}
			answers, err := client(
				"HuaQiang mai gua",
				"answer the following questions",
				questions, echo)
			if err != nil {
				return nil, err
			}
			if answers[0] == "2" && answers[2] == "sure" {
				return nil, nil
			}
			return nil, fmt.Errorf("wrong answer")
		})
	log.Fatalln(server.ListenAndServe(":2222"))
}

效果如下:

image-20220504164439048

另外对于身份认证,如果验证失败建议延迟几秒再返回 err,防止爆破。

关于 Context

这是一个作用域为单个客户端与服务器的整个连接过程的上下文,包含了网络信息、用户身份信息、以及其他信息。其中用户信息由 SSHServerLookupUser 回调函数来获取;Permission 身份认证信息由设计的身份认证的回调函数决定;其余的信息将会在建立连接时被填写;

另外用户自定义的请求处理回调函数总是应该正确的处理 Context.Done() 消息,以接受服务器的关闭消息从而正确地取消子协程任务。

添加 channel 处理回调函数

按照 RFC 4254,总共有四种类型的 ssh channel 请求,分别是 sessiondirect-tcpipforwarded-tcpip 以及 x11。当然一些客户端与服务端还会定义自己的请求类型。可通过 SSHServer 提供的 SetNewChanHandleFunc 为特定类型注册一个处理函数;

另外在 utils 包中,对 sessiondirect-tcpipforwarded-tcpip 有一个基本功能的实现;

DefaultSessionChanHandler

该类型用于处理 session 类型的 channel 请求,目前除了 subsystem ,其余的 RFC 4254 中定义的请求均已实现。

使用者可以通过该类型提供的 SetReqHandler 中定义的 SetReqHandler 来注册特定类型请求的处理函数,以监听、记录、过滤的用户的请求等。

通过 Start 方法对客户端通道建立的请求进行处理;

总是应该使用 NewSessionChannelHandler 函数创建一个 DefaultSessionChanHandler 实例;

:添加 session 类型的 channel 请求处理函数,使用 gosshd 提供的 NewSessionChannelHandler 去创建一个处理器,并为其设置一个 exec 类型的处理的回调函数,记录客户端想要执行的命令:

package main

import (
	"github.com/nishoushun/gosshd"
	"github.com/nishoushun/gosshd/utils"
	"log"
)

func main() {
	server, _ := utils.SimpleServerOnUnix()
	server.SetNewChanHandleFunc(gosshd.SessionTypeChannel, func(c gosshd.SSHNewChannel, ctx gosshd.Context) {
		handler := utils.NewSessionChannelHandler(1, 1, 1, 0)
		handler.SetReqHandler(gosshd.ReqExec,
			func(request gosshd.Request, session gosshd.Session) error {
				log.Printf("%s want exec cmd: %s \r\n", session.User().UserName, string(request.Payload))
				request.Reply(true, nil)
				handler.SendExitStatus(0, true, session)
				return nil
			})
		handler.Start(c, ctx)
	})
	log.Fatalln(server.ListenAndServe(":2222"))
}

运行效果如下:

image-20220504221259668

TcpIpDirector

该类型用于处理 direct-tcpip 类型的 channel,即打开客户端指定的远程连接,并将通道内容转发至远程目标;

一个最经典的例子就是 ssh -L local-addr:local-port:remote-addr:remote-port 选项,客户端会监听 local-addr:local-port,并将内容通过 SSH 连接转发至服务器,服务器再将其转发至 remote-addr:remote-port,其底层就是通过 direct-tcpip 类型的 channel 传输数据。

:为新创建的 server 注册一个由 TcpIpDirector 实现的 NewChanHandleFunc

package main

import (
	"github.com/nishoushun/gosshd"
	"github.com/nishoushun/gosshd/utils"
	"log"
)

func main() {
	server, _ := utils.SimpleServerOnUnix()
	server.SetNewChanHandleFunc(gosshd.DirectTcpIpChannel, utils.NewTcpIpDirector(0).HandleDirectTcpIP)
	log.Fatalln(server.ListenAndServe(":2222"))
}

开启 docker 容器进行测试:

image-20220504221816307

未开启端口映射的情况下,只能通过 docker 的虚拟网卡地址访问web服务:

image-20220504221841279

开服务端并转发:

image-20220504222643254

添加全局请求处理回调函数

RFC 4254 4. 中定义了全局请求处理,通过 SSHServerSetGlobalRequestHandleFunc 方法可注册一个全局请求类型的处理函数。

:为服务器添加 tcpip-forwardcancel-tcpip-forward 全局请求的处理器

package main

import (
	"github.com/nishoushun/gosshd"
	"github.com/nishoushun/gosshd/utils"
	"log"
)

func main() {
	server, _ := utils.SimpleServerOnUnix()
	fhandler := NewForwardedTcpIpHandler(0)
	server.SetGlobalRequestHandleFunc(gosshd.GlobalReqTcpIpForward, fhandler.ServeForward)
	server.SetGlobalRequestHandleFunc(gosshd.GlobalReqCancelTcpIpForward, fhandler.CancelForward)
	log.Fatalln(server.ListenAndServe(":2222"))
}

Documentation

Index

Constants

View Source
const (
	SessionTypeChannel    = "session"         // session 类型的 channel open 请求. RFC 4254 6.1.
	DirectTcpIpChannel    = "direct-tcpip"    // direct-tcpip 类型的 channel open 请求. RFC 4254 7.2.
	X11Channel            = "x11"             // x11 类型的 channel open 请求. RFC 4254 6.3.2
	ForwardedTCPIPChannel = "forwarded-tcpip" // forwarded-tcpip 类型的 channel open 请求. RFC 4254 7.2.
)

RFC 4254 规定的 4 种 channel 类型

View Source
const (
	Prohibited         RejectionReason = 1
	ConnectionFailed                   = 2
	UnknownChannelType                 = 3
	ResourceShortage                   = 4
)
View Source
const (
	GlobalReqTcpIpForward       = "tcpip-forward"
	GlobalReqCancelTcpIpForward = "cancel-tcpip-forward"

	ForwardedTcpIpChannelType = "forwarded-tcpip"
)
View Source
const (
	ReqShell     = "shell"
	ReqPty       = "pty-req"
	ReqExec      = "exec"
	ReqWinCh     = "window-change"
	ReqEnv       = "env"
	ReqSignal    = "signal"
	ReqSubsystem = "subsystem"
	ReqExit      = "exit"
	ExitStatus   = "exit-status"
)
View Source
const (
	Version1 = "SSH-1.0-"
	Version2 = "SSH-2.0-"
)

Variables

View Source
var NoContextBuilderErr = errors.New("no context builder")
View Source
var PreferredCiphers = []string{
	"aes128-gcm@openssh.com",
	"chacha20-poly1305@openssh.com",
	"aes128-ctr", "aes192-ctr", "aes256-ctr",
}

PreferredCiphers 默认使用的加密算法

View Source
var PreferredKexAlgos = []string{
	kexAlgoCurve25519SHA256, kexAlgoCurve25519SHA256LibSSH,
	kexAlgoECDH256, kexAlgoECDH384, kexAlgoECDH521,
	kexAlgoDH14SHA256, kexAlgoDH14SHA1,
}

PreferredKexAlgos 默认的密钥交换算法

View Source
var Signals = map[Signal]int{
	SIGABRT: 6,
	SIGALRM: 14,
	SIGFPE:  8,
	SIGHUP:  1,
	SIGILL:  4,
	SIGINT:  2,
	SIGKILL: 9,
	SIGPIPE: 13,
	SIGQUIT: 3,
	SIGSEGV: 11,
	SIGTERM: 15,
}
View Source
var SupportedCiphers = []string{
	"aes128-ctr", "aes192-ctr", "aes256-ctr",
	"aes128-gcm@openssh.com",
	"chacha20-poly1305@openssh.com",
	"arcfour256", "arcfour128", "arcfour",
	"aes128-cbc",
	"3des-cbc",
}

SupportedCiphers 支持的加密算法

View Source
var SupportedMACs = []string{
	"hmac-sha2-256-etm@openssh.com", "hmac-sha2-256", "hmac-sha1", "hmac-sha1-96",
}

SupportedMACs 支持的消息摘要算法

Functions

func DiscardRequests

func DiscardRequests(ctx Context, in <-chan *ssh.Request)

DiscardRequests 拒绝所有的 Request,可由 ctx 取消执行

func WrapAuthLogCallback

func WrapAuthLogCallback(callback AuthLogCallback) func(conn ssh.ConnMetadata, method string, err error)

WrapAuthLogCallback 生成 ssh.ServerConfig 可接受的参数函数:AuthLogCallback

func WrapBannerCallback

func WrapBannerCallback(callback BannerCallback) func(conn ssh.ConnMetadata) string

WrapBannerCallback 生成 ssh.ServerConfig 可接受的参数函数:BannerCallback

func WrapKeyboardInteractiveChallenger

func WrapKeyboardInteractiveChallenger(callback KeyboardInteractiveChallengeCallback) func(conn ssh.ConnMetadata, client ssh.KeyboardInteractiveChallenge) (*ssh.Permissions, error)

WrapKeyboardInteractiveChallenger 生成 ssh.ServerConfig 可接受的参数:KeyboardInteractiveChallengeCallback

func WrapPasswdCallback

func WrapPasswdCallback(callback PasswdCallback) func(conn ssh.ConnMetadata, password []byte) (*ssh.Permissions, error)

WrapPasswdCallback 生成 ssh.ServerConfig 可接受的函数参数:PasswordCallback

func WrapPublicKeyCallback

func WrapPublicKeyCallback(callback PublicKeyCallback) func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error)

WrapPublicKeyCallback 生成 ssh.ServerConfig 可接受的参数:PublicKeyCallback

Types

type AuthLogCallback

type AuthLogCallback func(conn ConnMetadata, method string, err error)

AuthLogCallback ssh 包下定义的身份认证回调函数被调用时的回调函数的包装

type BannerCallback

type BannerCallback func(metadata ConnMetadata) string

BannerCallback 当建立 SSH 连接时,在身份认证之前向客户端发送的字符串信息 注意:并不是所有的客户端都会对该信息进行处理

type Channel

type Channel interface {
	ssh.Channel
}

type ChannelOpenDirectMsg

type ChannelOpenDirectMsg struct {
	Dest  string // host to connect
	DPort uint32 // port to connect
	Src   string // originator IP address
	SPort uint32 // originator port
}

ChannelOpenDirectMsg 客户端发送的 channel 建立请求中附带的额外数据,用于指明转发地址与端口 RFC 4254 7.2.

type ConnMetadata

type ConnMetadata interface {
	ssh.ConnMetadata
}

ConnMetadata 身份认证时,客户端提供的信息

type Context

type Context interface {
	context.Context // 用于存储键值数据,以及获取该 context 实例相关 cancel,使退出 handler 函数的执行
	sync.Locker     // 不同处理器争夺临界资源时可能会用到

	SetValue(name interface{}, data interface{})
	SetClientVersion(version string)
	SetConn(conn ssh.Conn)
	SetServerVersion(version string)
	// SetPermissions 应在 ssh 身份验证的回调函数中进行填充
	SetPermissions(permissions *Permissions)
	SetLocalAddr(addr net.Addr)
	SetRemoteAddr(addr net.Addr)
	SetUser(user *User)

	User() *User
	ClientVersion() string
	ServerVersion() string
	RemoteAddr() net.Addr
	LocalAddr() net.Addr

	// Permissions 用于身份验证回调函数的返回值,包含用户的权限信息,取决于具体的身份认证 callback 实现
	Permissions() *Permissions
	Conn() ssh.Conn
	Server() *SSHServer
}

Context 包含各类 handler 所需信息以及一个 context.Context ,必要信息应该保证在 handler 调用之前被添加。 Context 的作用域为单个客户端的整个连接过程。

func NewContext

func NewContext(sshd *SSHServer) (Context, context.CancelFunc)

NewContext 创建一个 SSHContext

type ContextBuilder

type ContextBuilder func(sshd *SSHServer) (Context, context.CancelFunc)

type ExecMsg

type ExecMsg struct {
	Command string
}

type GlobalRequestCallback

type GlobalRequestCallback func(ctx Context, request Request)

GlobalRequestCallback 当成功建立连接后,对于全局请求的处理,例如 “tcpip-forward” 以及 “cancel-tcpip-forward“ 等请求处理, 这类要求通常是为了客户端让服务端向客户端打开一个通道,进行数据转发。

type KeyboardInteractiveChallenge

type KeyboardInteractiveChallenge func(name, instruction string, questions []string, echos []bool) (answers []string, err error)

KeyboardInteractiveChallenge ssh 定义的轮询问答认证回调函数

type KeyboardInteractiveChallengeCallback

type KeyboardInteractiveChallengeCallback func(conn ConnMetadata, client KeyboardInteractiveChallenge) (*Permissions, error)

KeyboardInteractiveChallengeCallback ssh 包下定义的公钥认证回调函数类型的包装

type LookupUserCallback

type LookupUserCallback func(metadata ConnMetadata) (*User, error)

LookupUserCallback 根据用户名,获取用户详细数据实例

type NewChannel

type NewChannel interface {
	ssh.NewChannel
}

type NewChannelHandleFunc

type NewChannelHandleFunc func(ctx Context, channel NewChannel)

type PasswdCallback

type PasswdCallback func(conn ConnMetadata, password []byte) (*Permissions, error)

PasswdCallback ssh 包下定义的密码认证回调函数类型的包装

type Permissions

type Permissions struct {
	CriticalOptions map[string]string
	Extensions      map[string]string
}

Permissions 用于保存身份认证信息,最终会被存到 Context 中

type PermitNotAllowedError

type PermitNotAllowedError struct {
	Msg string
}

func (PermitNotAllowedError) Error

func (e PermitNotAllowedError) Error() string

type PlatformNotSupportError

type PlatformNotSupportError struct {
	Function string
}

func (PlatformNotSupportError) Error

func (e PlatformNotSupportError) Error() string

type PtyRequestMsg

type PtyRequestMsg struct {
	Term     string
	Columns  uint32
	Rows     uint32
	Width    uint32
	Height   uint32
	Modelist string
}

type PtyWindowChangeMsg

type PtyWindowChangeMsg struct {
	Columns uint32
	Rows    uint32
	Width   uint32
	Height  uint32
}

type PublicKey

type PublicKey interface {
	ssh.PublicKey
}

type PublicKeyCallback

type PublicKeyCallback func(conn ConnMetadata, key PublicKey) (*Permissions, error)

PublicKeyCallback ssh 包下定义的公钥认证回调函数类型的包装

type RejectionReason

type RejectionReason uint32

RejectionReason 拒绝客户端通道建立请求的原因, 定义于 RFC 4254 5.1.

type RemoteForwardCancelRequestMsg

type RemoteForwardCancelRequestMsg struct {
	BindAddr string
	BindPort uint32
}

type RemoteForwardChannelDataMsg

type RemoteForwardChannelDataMsg struct {
	DestAddr   string
	DestPort   uint32
	OriginAddr string
	OriginPort uint32
}

type RemoteForwardRequestMsg

type RemoteForwardRequestMsg struct {
	BindAddr string
	BindPort uint32
}

type RemoteForwardSuccessMsg

type RemoteForwardSuccessMsg struct {
	BindPort uint32
}

type Request

type Request struct {
	*ssh.Request
}

Request ssh 包 Request 类型指针的包装

type SSHConn

type SSHConn interface {
	ssh.Conn
}

type SSHConnFailedLogCallback

type SSHConnFailedLogCallback func(reason error, conn net.Conn)

SSHConnFailedLogCallback 尝试建立 SSH 连接失败之后,要立即执行的回调函数,用于记录失败信息等

type SSHConnLogCallback

type SSHConnLogCallback func(ctx Context) error

SSHConnLogCallback 建立 SSH 连接成功之后,要立即执行的回调函数。 此时的 sshCtx 中已经包含了基本的数据; 当该函数返回的 error 不为 nil 时,将会停止下一步,且 SSH 连接会被关闭。

type SSHContext

type SSHContext struct {
	context.Context // 应该用于退出该 context 实例相关的 handler 函数的执行
	sync.Mutex
	// contains filtered or unexported fields
}

SSHContext 基本的上下文

func (*SSHContext) ClientVersion

func (ctx *SSHContext) ClientVersion() string

func (*SSHContext) Conn

func (ctx *SSHContext) Conn() ssh.Conn

func (*SSHContext) LocalAddr

func (ctx *SSHContext) LocalAddr() net.Addr

func (*SSHContext) Permissions

func (ctx *SSHContext) Permissions() *Permissions

func (*SSHContext) RemoteAddr

func (ctx *SSHContext) RemoteAddr() net.Addr

func (*SSHContext) Server

func (ctx *SSHContext) Server() *SSHServer

func (*SSHContext) ServerVersion

func (ctx *SSHContext) ServerVersion() string

func (*SSHContext) SessionID

func (ctx *SSHContext) SessionID() string

func (*SSHContext) SetClientVersion

func (ctx *SSHContext) SetClientVersion(version string)

func (*SSHContext) SetConn

func (ctx *SSHContext) SetConn(conn ssh.Conn)

func (*SSHContext) SetLocalAddr

func (ctx *SSHContext) SetLocalAddr(addr net.Addr)

func (*SSHContext) SetPermissions

func (ctx *SSHContext) SetPermissions(permissions *Permissions)

func (*SSHContext) SetRemoteAddr

func (ctx *SSHContext) SetRemoteAddr(addr net.Addr)

func (*SSHContext) SetServerVersion

func (ctx *SSHContext) SetServerVersion(version string)

func (*SSHContext) SetUser

func (ctx *SSHContext) SetUser(user *User)

func (*SSHContext) SetValue

func (ctx *SSHContext) SetValue(key, value interface{})

SetValue 设置值,会上锁

func (*SSHContext) UseConnMeta

func (ctx *SSHContext) UseConnMeta(meta ConnMetadata)

func (*SSHContext) User

func (ctx *SSHContext) User() *User

type SSHServer

type SSHServer struct {
	*sync.Mutex

	ssh.ServerConfig // ssh 包下的 ServerConfig

	ContextBuilder // 用于生成自定义的 Context

	// 用于建立连接后,通过用户名,找到用户信息,如果返回的 err 不为 nil,则将终止连接
	LookupUserCallback

	// 该字段作用于身份认证之前,对服务器接受的网络连接接口实例进行相应操作,
	// 用于设置超时、原始数据处理等,也可以返回相应的接口升级实例;如果返回 error 不为 nil 则将终止该连接。
	TransformConnCallback
	SSHConnFailedLogCallback                                  // 用于记录 ssh 建立失败原因
	SSHConnLogCallback                                        // 建立 ssh 连接后的处理函数,如果返回 error 不为 nil,则终止连接
	GlobalRequestHandlers    map[string]GlobalRequestCallback // 建立 ssh 连接后的处理全局的 request;如果未设置则拒绝其请求

	// 当接收到客户端通道建立请求是,会根据类型由对应的回调函数进行处理。
	NewChannelHandlers map[string]NewChannelHandleFunc // 当 ChannelHandlers 中不存在对应类型 channel 的处理器时,由该 handler 进行处理
	// contains filtered or unexported fields
}

func NewSSHServer

func NewSSHServer() *SSHServer

NewSSHServer 初始化并返回一个 SSHServer 实例

func (*SSHServer) AddHostKey

func (sshd *SSHServer) AddHostKey(hostKey []byte) error

AddHostKey 加载密钥,hostkey 应该是服务端私钥文件的全部内容 返回的 err 不为 nil 说明密钥内容解析失败。

func (*SSHServer) AddHostSigner

func (sshd *SSHServer) AddHostSigner(signer Signer)

AddHostSigner 加载 Signer 形式的密钥, 返回的 err 不为 nil 说明密钥内容解析失败。

func (*SSHServer) Close

func (sshd *SSHServer) Close() error

Close 关闭服务器网络监听器,关闭所有的已经建立的 SSH 连接 注意:该方法并不保证 ChannelHandler 与 RequestHandler 运行时开启的协程被取消,这取决于传入的接口的实现方式, 所以需要保证开启的协程可以成功接收到 Context Done() 方法的信号,并退出协程

func (*SSHServer) DelSSHConn

func (sshd *SSHServer) DelSSHConn(conn SSHConn)

DelSSHConn 执行 conn 对应的cancel 并删除 conn

func (*SSHServer) HandleConn

func (sshd *SSHServer) HandleConn(conn net.Conn)

func (*SSHServer) ListenAndServe

func (sshd *SSHServer) ListenAndServe(address string) error

ListenAndServe 监听tcp网络并启动 SSH 服务 network 为 "tcp", "tcp4", "tcp6", "unix" or "unixpacket"

func (*SSHServer) LoadHostKey

func (sshd *SSHServer) LoadHostKey(path string) error

LoadHostKey 从指定的文件中加载密钥, 返回的 err 不为 nil 说明密钥内容解析失败。

func (*SSHServer) NewChannel

func (sshd *SSHServer) NewChannel(ctype string, handleFunc NewChannelHandleFunc)

NewChannel 添加对应类型的 channel 请求处理函数

func (*SSHServer) NewGlobalRequest

func (sshd *SSHServer) NewGlobalRequest(ctype string, handleFunc GlobalRequestCallback)

NewGlobalRequest 添加对应类型的 global request 请求处理函数

func (*SSHServer) Serve

func (sshd *SSHServer) Serve(listener net.Listener) error

Serve 使用传入的监听器进行监听,并启动 SSH 服务

func (*SSHServer) SetAuthLogCallback

func (sshd *SSHServer) SetAuthLogCallback(cb AuthLogCallback)

SetAuthLogCallback SSH 服务器与客户端进行身份认证时,调用的函数;可以利用该回调函数记录连接信息与验证方式,并做出对应处理

func (*SSHServer) SetBannerCallback

func (sshd *SSHServer) SetBannerCallback(cb BannerCallback)

SetBannerCallback 当服务器成功与客户端建立 SSH 连接时,发送至给客户端的字符串信息。

func (*SSHServer) SetKeyboardInteractiveChallengeCallback

func (sshd *SSHServer) SetKeyboardInteractiveChallengeCallback(cb KeyboardInteractiveChallengeCallback)

SetKeyboardInteractiveChallengeCallback 设置轮询问答认证处理回调函数

func (*SSHServer) SetPasswdCallback

func (sshd *SSHServer) SetPasswdCallback(cb PasswdCallback)

SetPasswdCallback 设置密码认证处理回调函数

func (*SSHServer) SetPublicKeyCallback

func (sshd *SSHServer) SetPublicKeyCallback(cb PublicKeyCallback)

SetPublicKeyCallback 设置主机公钥认证处理回调

func (*SSHServer) SetVersion

func (sshd *SSHServer) SetVersion(version int, suffix string)

SetVersion 设置服务端版本号,1 表示 'SSH-1.0-';其它 表示 'SSH-2.0-'; suffix 为紧跟着版本号的后缀。

func (*SSHServer) Shutdown

func (sshd *SSHServer) Shutdown() error

Shutdown 关闭服务器,调用所有连接产生的 cancelFunc,尝试取消所有的处理协程

type SetenvRequest

type SetenvRequest struct {
	Name  string
	Value string
}

type Signal

type Signal string
const (
	SIGABRT Signal = "ABRT"
	SIGALRM Signal = "ALRM"
	SIGFPE  Signal = "FPE"
	SIGHUP  Signal = "HUP"
	SIGILL  Signal = "ILL"
	SIGINT  Signal = "INT"
	SIGKILL Signal = "KILL"
	SIGPIPE Signal = "PIPE"
	SIGQUIT Signal = "QUIT"
	SIGSEGV Signal = "SEGV"
	SIGTERM Signal = "TERM"
	SIGUSR1 Signal = "USR1"
	SIGUSR2 Signal = "USR2"
)

func (Signal) Signal

func (s Signal) Signal()

func (Signal) String

func (s Signal) String() string

type SignalMsg

type SignalMsg struct {
	Signal Signal
}

type Signer

type Signer interface {
	ssh.Signer
}

type SubsystemRequestMsg

type SubsystemRequestMsg struct {
	Subsystem string
}

type TransformConnCallback

type TransformConnCallback func(net.Conn) (net.Conn, error)

TransformConnCallback listener 监听并接受一个网络连接后,要立即执行的回调函数;返回 当返回的 error 不为 nil 时,将停止继续处理并关闭该网络连接

type User

type User struct {
	UserName     string            // 用户名
	PasswordFlag string            // 密码标志位
	Uid          string            // 用户id
	Gid          string            // 用户组id
	GECOS        string            // 用户描述
	HomeDir      string            // 用户的主目录
	Shell        string            // 用户的默认shell
	Extensions   map[string]string // 可能会用到的额外信息
}

User 根据 Unix 系统的 passwd 文件设置的用户字段结构体

type UserNotExistError

type UserNotExistError struct {
	User string
}

func (UserNotExistError) Error

func (e UserNotExistError) Error() string

Directories

Path Synopsis
serv module
utils module

Jump to

Keyboard shortcuts

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