Skip to content

Convenient wrapper around go's core implementation of golang.org/x/crypto/ssh

License

Notifications You must be signed in to change notification settings

gurshafriri/go-sshclient

 
 

Repository files navigation

WAT

A wrapper around go's core implementation of golang.org/x/crypto/ssh to make ssh and scp usage more convenient in the regular cases you need it

Library usage

Please see the examples here

Detailed

For ssh key based auth use this

package mystuff

import (
	"github.com/eugenmayer/go-sshclient/sshwrapper"
	"log"
)

func Run(cmd string) {
    sshApi, err := sshwrapper.DefaultSshApiSetup("somehost", 22, "root","/home/me/.ssh/id_rsa")    
    if err != nil {
        log.Fatal(err)
    }
    
    stdout, stderr, err := sshApi.Run(cmd)
    if err != nil {
        log.Print(stdout)
        log.Print(stderr)
        log.Fatal(err)
    }
}

If you want to use your local ssh agent

package mystuff

import (
	"github.com/eugenmayer/go-sshclient/sshwrapper"
	"log"
)

func Run(cmd string) {
	sshApi, err := sshwrapper.DefaultSshApiSetup("somehost", 22, "root","")    
    if err != nil {
        log.Fatal(err)
    }
    
    stdout, stderr, err := sshApi.Run(cmd)
    if err != nil {
        log.Print(stdout)
        log.Print(stderr)
        log.Fatal(err)
    }
}

And if you want to use (why..please why..) password based connection

package mystuff

import (
	"github.com/eugenmayer/go-sshclient/sshwrapper"
	"log"
)

func Run(cmd string) {
    sshApi, err := sshwrapper.DefaultSshApiSetup("somehost", 22, "root","")
    sshApi.Password = "test"
    // now override the auth config with a password baed config
    err = sshApi.DefaultSshPasswordSetup()
    if err != nil {
        log.Fatal(err)
    }
    
    stdout, stderr, err := sshApi.Run(cmd)
    if err != nil {
        log.Print(stdout)
        log.Print(stderr)
        log.Fatal(err)
    }
}

Tests

You need docker

make run-tests

About

Convenient wrapper around go's core implementation of golang.org/x/crypto/ssh

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 98.1%
  • Shell 1.3%
  • Makefile 0.6%