sshsudo

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2022 License: MIT Imports: 8 Imported by: 0

README

go-sshsudo

SSH with sudo.

This operates by opening a shell and feeding it commands after sudo.

It also does a preflight check to see if a password will be required for a shell so that it may bypass the password entry portion.

Testing

The test suite will spin up docker containers to test over a real simulated session. You will need to have docker installed and configured to be able to run a container in order to run go test.

License

See LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoReadyFlag = errors.New("no READY flag found when expected")
View Source
var ErrNoSudoPrompt = errors.New("no sudo prompt found when expected")

Functions

func CheckSudoNeedsPassword

func CheckSudoNeedsPassword(client *ssh.Client) (bool, error)

func SudoRun

func SudoRun(client *ssh.Client, passwordCallback SudoPasswordCallback, command ...string) (
	io.WriteCloser,
	io.Reader,
	io.Reader,
	*ssh.Session,
	error,
)

run a command with sudo over the ssh client

passwordCallback will be called if a sudo password is needed.

the command will be run in a shell with all elements quoted to prevent word splitting or expansion. use eval to achieve this if needed.

func SudoShell

func SudoShell(client *ssh.Client, passwordCallback SudoPasswordCallback) (
	io.WriteCloser,
	io.Reader,
	io.Reader,
	*ssh.Session,
	error,
)

open a shell with sudo on the ssh client

passwordCallback will be called if a sudo password is needed.

Types

type PasswordCallbackFailureError

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

func (PasswordCallbackFailureError) Error

func (PasswordCallbackFailureError) Is

func (PasswordCallbackFailureError) Unwrap

type SudoPasswordCallback

type SudoPasswordCallback func() (string, error)

func SudoStaticPasswordCallback

func SudoStaticPasswordCallback(pwd string) SudoPasswordCallback

Jump to

Keyboard shortcuts

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