ssh

package
v0.0.0-...-75eff44 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Author: yangzq80@gmail.com Date: 2021-05-07

Author: yangzq80@gmail.com Date: 2021-04-19

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WsSsh

func WsSsh(c *gin.Context)

handle webSocket connection. browser(data) -> webSocket -> ssh connection -> ssh server ssh server(data) -> ssh connection -> webSocket -> browser

Types

type Client

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

A Client implements an SSH client that supports running commands and scripts remotely.

func Dial

func Dial(network, addr string, config *ssh.ClientConfig) (*Client, error)

Dial starts a client connection to the given SSH server. This wraps ssh.Dial.

func DialWithKey

func DialWithKey(addr, user, keyfile string) (*Client, error)

DialWithKey starts a client connection to the given SSH server with key authmethod.

func DialWithKeyWithPassphrase

func DialWithKeyWithPassphrase(addr, user, keyfile string, passphrase string) (*Client, error)

DialWithKeyWithPassphrase same as DialWithKey but with a passphrase to decrypt the private key

func DialWithPasswd

func DialWithPasswd(addr, user, passwd string) (*Client, error)

DialWithPasswd starts a client connection to the given SSH server with passwd authmethod.

func (*Client) Close

func (c *Client) Close() error

Close closes the underlying client network connection.

func (*Client) Cmd

func (c *Client) Cmd(cmd string) *RemoteScript

Cmd creates a RemoteScript that can run the command on the client. The cmd string is split on newlines and each line is executed separately.

func (*Client) Script

func (c *Client) Script(script string) *RemoteScript

Script creates a RemoteScript that can run the script on the client.

func (*Client) ScriptFile

func (c *Client) ScriptFile(fname string) *RemoteScript

ScriptFile creates a RemoteScript that can read a local script file and run it remotely on the client.

func (*Client) Shell

func (c *Client) Shell() *RemoteShell

Shell create a noninteractive shell on client.

func (*Client) Terminal

func (c *Client) Terminal(config *TerminalConfig) *RemoteShell

Terminal create a interactive shell on client.

func (*Client) UnderlyingClient

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

UnderlyingClient get the underlying client.

type RemoteScript

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

A RemoteScript represents script that can be run remotely.

func (*RemoteScript) Cmd

func (rs *RemoteScript) Cmd(cmd string) *RemoteScript

Cmd appends a command to the RemoteScript.

func (*RemoteScript) Output

func (rs *RemoteScript) Output() ([]byte, error)

Output runs the script on the client and returns its standard output.

func (*RemoteScript) Run

func (rs *RemoteScript) Run() error

Run runs the script on the client.

The returned error is nil if the command runs, has no problems copying stdin, stdout, and stderr, and exits with a zero exit status.

func (*RemoteScript) SetStdio

func (rs *RemoteScript) SetStdio(stdout, stderr io.Writer) *RemoteScript

SetStdio specifies where its standard output and error data will be written.

func (*RemoteScript) SmartOutput

func (rs *RemoteScript) SmartOutput() ([]byte, error)

SmartOutput runs the script on the client. On success, its standard ouput is returned. On error, its standard error is returned.

type RemoteShell

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

A RemoteShell represents a login shell on the client.

func (*RemoteShell) SetStdio

func (rs *RemoteShell) SetStdio(stdin io.Reader, stdout, stderr io.Writer) *RemoteShell

SetStdio specifies where the its standard output and error data will be written.

func (*RemoteShell) Start

func (rs *RemoteShell) Start() error

Start starts a remote shell on client.

type SshConn

type SshConn struct {
	// calling Write() to write data into ssh server
	StdinPipe io.WriteCloser
	// Write() be called to receive data from ssh server
	ComboOutput *wsBufferWriter
	Session     *ssh.Session
}

connect to ssh server using ssh session.

func NewSshConn

func NewSshConn(cols, rows int, sshClient *ssh.Client) (*SshConn, error)

setup ssh shell session set Session and StdinPipe here, and the Session.Stdout and Session.Sdterr are also set.

func (*SshConn) Close

func (s *SshConn) Close()

func (*SshConn) ReceiveWsMsg

func (ssConn *SshConn) ReceiveWsMsg(wsConn *websocket.Conn, logBuff *bytes.Buffer, exitCh chan bool)

ReceiveWsMsg receive websocket msg do some handling then write into ssh.session.stdin

func (*SshConn) SendComboOutput

func (ssConn *SshConn) SendComboOutput(wsConn *websocket.Conn, exitCh chan bool)

func (*SshConn) SessionWait

func (ssConn *SshConn) SessionWait(quitChan chan bool)

type TerminalConfig

type TerminalConfig struct {
	Term   string
	Height int
	Weight int
	Modes  ssh.TerminalModes
}

A TerminalConfig represents the configuration for an interactive shell session.

Jump to

Keyboard shortcuts

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