ssh

package
v1.0.20250928075430 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthMode

type AuthMode int8

AuthMode SSH认证模式

const (
	AuthModePassword AuthMode = 1 // 密码认证
	AuthModeKey      AuthMode = 2 // 密钥认证
)

type Client

type Client interface {
	// Connect 建立SSH连接
	Connect(config *Config) error
	// Run 执行单个命令
	Run(command string) (string, error)
	// CreateSession 创建新的SSH会话
	CreateSession(userID int) error
	// GetSession 获取用户会话
	GetSession(userID int) *ssh.Session
	// CloseSession 关闭指定用户会话
	CloseSession(userID int) error
	// AddPublicKey 添加公钥到远程主机
	AddPublicKey(publicKey string) error
	// Close 关闭SSH客户端
	Close() error
	// WebTerminal 提供Web终端功能
	WebTerminal(userID int, conn *websocket.Conn) error
}

Client SSH客户端接口

func NewClient

func NewClient(logger *zap.Logger) Client

NewClient 创建SSH客户端

type Config

type Config struct {
	Host     string   `json:"host"`     // 服务器地址
	Port     int      `json:"port"`     // SSH端口,默认22
	Username string   `json:"username"` // 用户名
	Password string   `json:"password"` // 密码(密码认证时使用)
	Key      string   `json:"key"`      // 私钥内容(密钥认证时使用)
	Mode     AuthMode `json:"mode"`     // 认证方式
	Timeout  int      `json:"timeout"`  // 连接超时时间(秒),默认10
}

Config SSH连接配置

type TerminalReader

type TerminalReader struct {
	// contains filtered or unexported fields
}

TerminalReader 实现从WebSocket读取数据的io.Reader接口

func (*TerminalReader) Read

func (r *TerminalReader) Read(p []byte) (n int, err error)

Read 从WebSocket读取用户输入的命令数据

type TerminalWriter

type TerminalWriter struct {
	// contains filtered or unexported fields
}

TerminalWriter 实现向WebSocket写入数据的io.Writer接口

func (*TerminalWriter) Write

func (w *TerminalWriter) Write(p []byte) (n int, err error)

Write 向WebSocket发送终端输出数据

Jump to

Keyboard shortcuts

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