ssh

package module
v0.0.0-...-618c713 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: MIT Imports: 11 Imported by: 0

README

sshTunnel

Description

ssh tunnel forwarding library for Go. Implemented using golang.org/x/crypto/ssh . Like linux command:

ssh -N -f -L 3307:remoteHost:3306 sshUsername@sshHostname

Installation

go get -u github.com/alwaysthanks/sshTunnel

Examples

1.simple ssh forwarding
sshTool, err := NewSSHTool(sshHostname, sshUsername, sshPassword, "")
if err != nil {

}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
proxyServer, err := NewTunnelServer(ctx, localAddr, remoteAddr, sshTool)
if err != nil {

}
//run ssh proxy
go proxyServer.Start()
//begin your service
2.use ssh connections pool
sshTool, err := NewSSHTool(sshHostname, sshUsername, sshPassword, "")
if err != nil {

}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
//here use ssh pool
proxyServer, err := NewTunnelServerWithPool(ctx, localAddr, remoteAddr, sshTool)
if err != nil {

}
//run ssh proxy
go proxyServer.Start()
//begin your service

License

View the LICENSE file

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSShController

func NewSShController(ctx context.Context, sshTool *SSHTool, remoteHost string) *sshController

Types

type SSHTool

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

func NewSSHTool

func NewSSHTool(hostname, username, password string, privatePath string) (*SSHTool, error)

NewSSHTool returned *SSHTool choose (password) or (privateKey) as remote ssh connect authority examples: hostname: 10.129.130.122:11229 username: Alice password: yourpassword privatePath:

func (*SSHTool) Connect

func (tool *SSHTool) Connect() (conn *ssh.Client, err error)

SSHTool Connect returned *ssh.Client which can be used for proxy

type TunnelServer

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

func NewTunnelServer

func NewTunnelServer(ctx context.Context, localHost, remoteHost string, sshTool *SSHTool) (*TunnelServer, error)

func (*TunnelServer) Start

func (server *TunnelServer) Start()

type TunnelServerV2

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

func NewTunnelServerWithPool

func NewTunnelServerWithPool(ctx context.Context, localHost, remoteHost string, sshTool *SSHTool) (*TunnelServerV2, error)

use ssh connection pool

func (*TunnelServerV2) Start

func (server *TunnelServerV2) Start()

Jump to

Keyboard shortcuts

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