ssh_toolkit

package
v0.0.0-...-e4664ba Latest Latest
Warning

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

Go to latest
Published: May 3, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

README

SSH Toolkit

This is a toolkit for performing various operations in remote servers using SSH. It will be wrapper around some required host level operations to be performed on remote servers.

Overall features -

  • Manage Pool of TCP connections to remote servers, so that we can reduce handshake time for each request.
  • ExecCommandOverSSH - Run any command. Alternative to exec.Command in Go.
  • NetConnOverSSH - Helper to run tcp or unix based http requests on remote server. It should return http.Client object for further operations, so that unix or tcp based http requests can be made.
  • CopyFileToRemoteServer - Copy files to remote server. Use rsync for this.
  • CopyFileFromRemoteServer - Copy files from remote server. Use rsync for this.

[!NOTE]
SSH Toolkit has a implementation of Pool of TCP connections to remote servers. This will help in reducing handshake time for each request. The remote servers should be configured to accept high number of sessions for single tcp connection.

Go to /etc/ssh/sshd_config and set MaxSessions to 20 or more. We need to keep it little bit higher than the number of workers configured in swiftwave to keep system stable. Else new session will be timed out and create new TCP connections which is costly and time-consuming.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFileFromRemoteServer

func CopyFileFromRemoteServer(
	remotePath string,
	localPath string,
	host string, port int, user string, privateKey string,
) error

func CopyFileToRemoteServer

func CopyFileToRemoteServer(
	localPath string,
	remotePath string,
	host string, port int, user string, privateKey string,
) error

func CopyFolderFromRemoteServer

func CopyFolderFromRemoteServer(
	remotePath string,
	localPath string,
	host string, port int, user string, privateKey string,
) error

func CopyFolderToRemoteServer

func CopyFolderToRemoteServer(
	localPath string,
	remotePath string,
	host string, port int, user string, privateKey string,
) error

func DeleteSSHClient

func DeleteSSHClient(host string)

func DirectSSH

func DirectSSH(
	ctx context.Context, initCol int, initRow int,
	host string, port int, user string, privateKey string) (
	session *ssh.Session, stdin *io.WriteCloser, stdout *io.Reader, stderr *io.Reader, err error)

DirectSSH opens a direct ssh connection to a server

func DirectSSHToContainer

func DirectSSHToContainer(
	ctx context.Context, initCol int, initRow int, containerId string,
	dockerHost string, host string, port int, user string, privateKey string) (
	session *ssh.Session, stdin *io.WriteCloser, stdout *io.Reader, stderr *io.Reader, err error)

DirectSSHToContainer opens a direct ssh connection to a container

func ExecCommandOverSSH

func ExecCommandOverSSH(cmd string,
	stdoutBuf, stderrBuf *bytes.Buffer, sessionTimeoutSeconds int,
	host string, port int, user string, privateKey string,
) error

func ExecCommandOverSSHWithOptions

func ExecCommandOverSSHWithOptions(cmd string,
	stdoutBuf, stderrBuf *bytes.Buffer, sessionTimeoutSeconds int,
	host string, port int, user string, privateKey string,
	validate bool,
) error

func NetConnOverSSH

func NetConnOverSSH(
	network, address string, netTimeoutSeconds int,
	host string, port int, user string, privateKey string,
) (net.Conn, error)

func SetValidator

func SetValidator(validator ServerOnlineStatusValidator)

func UpdateTCPTimeout

func UpdateTCPTimeout(t int)

Types

type OperatingSystem

type OperatingSystem string
const (
	DebianBased OperatingSystem = "debian"
	FedoraBased OperatingSystem = "fedora"
)

func DetectOS

func DetectOS(sessionTimeoutSeconds int,
	host string, port int, user string, privateKey string) (OperatingSystem, error)

type ServerOnlineStatusValidator

type ServerOnlineStatusValidator func(host string) bool

Jump to

Keyboard shortcuts

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