A simple package to ssh into devices.
This package only supports authentication via username/password.
package main
import (
"fmt"
"log"
"os"
"github.com/montybeatnik/devcon"
)
// Example with Password
func main() {
client := devcon.NewClient(
os.Getenv("SSH_USER"),
"10.0.0.60",
devcon.Password(os.Getenv("SSH_PASSWORD")),
)
out, err := client.Run("show version")
if err != nil {
log.Fatalf("command failed: %v", err)
}
fmt.Println(out)
}
// Example with Private Key
func main() {
homeDir, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
}
keyFile := filepath.Join(homeDir, ".ssh/id_rsa")
if err != nil {
log.Fatal(err)
}
client := devcon.NewClient(
"rolodev",
"10.0.0.60",
devcon.PrivateKey(keyFile),
)
out, err := client.Run("show version")
if err != nil {
log.Fatalf("command failed: %v", err)
}
fmt.Println(out)
}
- [] Add support for public key auth.
- go test -v -run Run -cpuprofile cpu.prof -memprofile mem.prof -bench .
go test -v
go test -v -run RunCommand
go test -v -run Run
go test -run RunCommand -bench=.