bassh

package module
v0.0.1-alpha Latest Latest
Warning

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

Go to latest
Published: May 15, 2016 License: BSD-3-Clause Imports: 13 Imported by: 0

README

#go-bassh Go Report Card Build Status Coverage Status

go-bassh library can be used to quickly open a tty on a remote server, given username, .pem key (at the moment only key without passphrase, but soon the passphrase will be supported), the ip address of the machine, and the SSH port

####DISCLAIMER This small library is a prototype and I'm working on it while learning Go, therefore it's not intended to be used in any production environment whatsoever. Test coverage is low because I'm still learning how to write tests in Go, and it will take some time before achieving an acceptable level of coverage. Feel free to fork, make it better, and raise a pull request if you want to contribute.

###Usage example

package main

import (
	"github.com/thoeni/go-bassh"
)

func main() {
	sshConfig, _ := bassh.ConfigureCredentials("ubuntu", "/Users/johndoe/.ssh/myprivatekey.pem")
	client := bassh.CreateClient(sshConfig, "123.234.123.234", 22)
	client.RunBash()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigureCredentials

func ConfigureCredentials(username string, keypath string) (*ssh.ClientConfig, error)

ConfigureCredentials returns the ClientConfig struct to be used as part of the SSHClient definition

func RunBashInteractive

func RunBashInteractive()

RunBashInteractive allows the user to configure the SSH client interactively and executes /bin/bash on the remote host specified interactively by the user

Types

type SSHClient

type SSHClient struct {
	Session *ssh.Session
	Config  *ssh.ClientConfig
	Host    string
	Port    int
}

SSHClient wraps the ssh client configuration and the host/port information

func CreateClient

func CreateClient(sshConfig *ssh.ClientConfig, ipAddr string, port int) *SSHClient

CreateClient takes a *ssh.ClientConfig struct as input, ipAddress of the target machine and the ssh port, and returns an *SSHClient where a command can be Run on

func (*SSHClient) CloseSession

func (client *SSHClient) CloseSession()

CloseSession closes the session for the client

func (*SSHClient) InitSession

func (client *SSHClient) InitSession(params *SSHParams) error

InitSession returns a session initialised with the given params

func (*SSHClient) Run

func (client *SSHClient) Run(command string)

Run opens an SSH session and Runs the command passed as an argument

func (*SSHClient) RunBash

func (client *SSHClient) RunBash()

RunBash runs /bin/bash on the client

type SSHParams

type SSHParams struct {
	Env    []string
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

SSHParams contains params to setup the Session

Jump to

Keyboard shortcuts

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