customizeSSHClient

package module
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

README

使用示例

package main

import (
	"fmt"

	customizeSSHClient "github.com/customize-ssh-client"
)

func main() {
	// 定义需要连接的远程主机信息(修改 IP 和端口信息)
	sshHost := "10.100.0.21"
	sshPort := "22"
	sshUser := "root"
	sshAddr := fmt.Sprintf("%v:%v", sshHost, sshPort)

	// 使用秘钥方式连接(修改私钥地址)
	id_rsa := "/root/.ssh/id_rsa"
	client := customizeSSHClient.SSHPrivateKey(sshAddr, sshUser, id_rsa)

	// 定义需要执行的命令在远程服务器上执行
	shellList := []string{
		"whoami",
		"ls -lha /root",
	}
	customizeSSHClient.ExecShell(client, shellList)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecShell

func ExecShell(client *ssh.Client, shellList []string)

执行定义的命令

func SSHPassword

func SSHPassword(sshAddr string, sshUser string, password string) *ssh.Client

使用密码方式连接 SSH 服务器

func SSHPrivateKey

func SSHPrivateKey(sshAddr string, sshUser string, id_rsa string) *ssh.Client

使用密钥方式连接 SSH 服务器

Types

This section is empty.

Jump to

Keyboard shortcuts

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