ssh

package
v0.0.0-...-7aedd83 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const SSHWorker = 10

SSHWorker 可以通过 gossh.SSHWorker 修改

Variables

This section is empty.

Functions

func GetAuthKeys

func GetAuthKeys(keys []string) []ssh.AuthMethod

GetAuthKeys key 认证

func GetAuthPassword

func GetAuthPassword(password string) []ssh.AuthMethod

GetAuthPassword 密码认证

func PublicKeyFile

func PublicKeyFile(file string) ssh.AuthMethod

PublicKeyFile 获取

Types

type ExecResult

type ExecResult struct {
	ID             int
	Host           string
	Command        string
	LocalFilePath  string
	RemoteFilePath string
	Result         string
	StartTime      time.Time
	EndTime        time.Time
	Error          error
}

ExecResult 命令执行结果详情结构体

func LocalExec

func LocalExec(cmd string, timeOutSecond int64) (ExecResult, error)

LocalExec 在本地执行命令,无需目标 host

func RemoteExec

func RemoteExec(command string, runUser string, port int, hosts []string, timeOutSecond int64) ([]ExecResult, error)

RemoteExec 执行远程命令,需要提供 hosts 列表

type HostSession

type HostSession struct {
	Username string
	Password string
	Hostname string
	Signers  []ssh.Signer
	Port     int
	Auths    []ssh.AuthMethod
}

HostSession session 信息结构体

func (*HostSession) Exec

func (exec *HostSession) Exec(id int, command string, config ssh.ClientConfig) *ExecResult

Exec execute the command and return a result structure

func (*HostSession) GenerateConfig

func (exec *HostSession) GenerateConfig() ssh.ClientConfig

GenerateConfig 生成配置

func (*HostSession) Transfer

func (exec *HostSession) Transfer(id int, localFilePath string, remoteFilePath string, config ssh.ClientConfig) *ExecResult

Transfer 使用 sftp 传输文件

type SSHExecAgent

type SSHExecAgent struct {
	Worker  int
	TimeOut time.Duration
}

SSHExecAgent worker

func (*SSHExecAgent) SFTPHostByKey

func (s *SSHExecAgent) SFTPHostByKey(hosts []string, port int, user string, localFilePath string, remoteFilePath string) ([]ExecResult, error)

SFTPHostByKey 通过 SFTP 协议传文件

func (*SSHExecAgent) SSHHostByKey

func (s *SSHExecAgent) SSHHostByKey(hosts []string, port int, user string, cmd string) ([]ExecResult, error)

SSHHostByKey 通过 key 认证

Jump to

Keyboard shortcuts

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