sshclient

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2022 License: Apache-2.0 Imports: 10 Imported by: 1

README

sshclient

Simple SSH client, the SSH connection is obtained through authentication.

Installation

go get -u github.com/coolstina/sshclient

Example

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/coolstina/sshclient"
)

func main() {
	host := os.Getenv("DESTINATION_SSH_HOST")         // example: 10.10.0.0:22
	username := os.Getenv("DESTINATION_SSH_USERNAME") // example: hello_world
	password := os.Getenv("DESTINATION_SSH_PASSWORD") // example: hello_world
	client, err := sshclient.NewClient(host, username, password)
	if err != nil {
		log.Fatalf("failed to init ssh client: %+v", err)
	}

	fmt.Println(client.Instance().User())
    
    defer client.Instance().Close()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(host string, username string, password string, options ...ClientConfigOption) (*Client, error)

NewClient Initialize SSH client instance, with host, username and password, host contains ip and port, for example: example.com:22, 10.10.10.10:22.

func (*Client) Instance

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

type ClientConfigOption added in v1.1.0

type ClientConfigOption interface {
	// contains filtered or unexported methods
}

ClientConfigOption implement option design model.

func WithSpecifyHostKeyCallback added in v1.1.0

func WithSpecifyHostKeyCallback(callback ssh.HostKeyCallback) ClientConfigOption

WithSpecifyHostKeyCallback Specify host key callback function.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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