ssh

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

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

Go to latest
Published: Sep 14, 2024 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSSHConfig

func NewSSHConfig(config Config) (*ssh.ClientConfig, error)

NewSSHConfig 根据提供的配置生成SSH客户端配置。 它支持通过密码、私钥内容或私钥文件路径三种方式来创建SSH连接。

参数

  • config: 包含了SSH连接所需的配置信息,包括用户类型、密码、私钥等。

返回值:

  • *ssh.ClientConfig 类型的SSH客户端配置指针,以及可能的错误信息。

Types

type Client

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

Client 结构体代表一个SSH客户端连接,它包含了一个指向ssh.Client的指针。

func Connect

func Connect(conf Config) (*Client, error)

Connect 根据提供的配置信息创建一个SSH客户端连接。 它支持通过密码、私钥内容或私钥文件路径三种方式来创建SSH连接。

参数

  • config: 包含了SSH连接所需的配置信息,包括用户类型、密码、私钥等。

返回值:

  • *ssh.ClientConfig 类型的SSH客户端配置指针,以及可能的错误信息。

func (Client) Client

func (c Client) Client() *ssh.Client

Client 方法返回当前客户端的 SSH 连接。

返回值是

  • *ssh.Client 类型,即一个指向 ssh.Client 实例的指针。

type Config

type Config struct {
	// Host SSH远程主机的IP地址或域名
	Host string
	// Port SSH远程主机的连接端口
	Port int
	// Type SSH连接的认证类型,包括密码、私钥内容或私钥文件路径三种方式
	Type ConfigType
	// User SSH远程主机的登录用户名
	User string
	// Password SSH远程主机的登录密码,仅在Type为ConfigTypeByPassword时生效
	Password string
	// PrivateKey SSH远程主机的私钥内容,仅在Type为ConfigTypeByPrivateKey时生效
	PrivateKey string
	// PrivateKeyPath SSH远程主机的私钥文件路径,仅在Type为ConfigTypeByPrivateKeyPath时生效
	PrivateKeyPath string
}

Config SSH连接配置信息结构体

type ConfigType

type ConfigType uint8

ConfigType ssh 连接支持的类型

const (
	// ConfigTypeByPassword 表示通过密码进行配置
	ConfigTypeByPassword ConfigType = iota
	// ConfigTypeByPrivateKey 表示通过私钥进行配置
	ConfigTypeByPrivateKey
	// ConfigTypeByPrivateKeyPath 表示通过私钥路径进行配置
	ConfigTypeByPrivateKeyPath
)

Jump to

Keyboard shortcuts

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