sshutil

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(cfg *ConnectConfig) (*ssh.Client, error)

Connect 建立 SSH 连接 认证优先级: 指定密钥 > 密码 > SSH Agent > 默认密钥路径

func RunCommand

func RunCommand(client *ssh.Client, command string) error

RunCommand 执行单条命令,stdout/stderr 实时回显

func RunCommandOutput

func RunCommandOutput(client *ssh.Client, command string) (string, error)

RunCommandOutput 执行命令并捕获输出(不回显)

func RunScript

func RunScript(client *ssh.Client, script string) error

RunScript 通过 stdin 传入多行脚本执行,实时回显

Types

type ConnectConfig

type ConnectConfig struct {
	Host     string // IP 或域名
	Port     int    // 默认 22
	User     string // 默认 root
	Password string // 密码认证
	KeyPath  string // 私钥路径
}

ConnectConfig SSH 连接参数

func (*ConnectConfig) Addr

func (c *ConnectConfig) Addr() string

Addr 返回 host:port

Jump to

Keyboard shortcuts

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