pyama86 / sshc

sshc.NewClient() returns *ssh.Client using ssh_config(5)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sshc Build Status codecov GoDoc

sshc.NewClient() returns *ssh.Client using ssh_config(5)

Usage

Describe ~/.ssh/config.

Host myhost
  HostName 203.0.113.1
  User k1low
  Port 10022
  IdentityFile ~/.ssh/myhost_rsa

Use sshc.NewClient() as follows

package main

import (
	"bytes"
	"log"

	"github.com/k1LoW/sshc"
)

func main() {
	client, err := sshc.NewClient("myhost")
	if err != nil {
		log.Fatalf("error: %v", err)
	}
	session, err := client.NewSession()
	if err != nil {
		log.Fatalf("error: %v", err)
	}
	defer session.Close()
	var stdout = &bytes.Buffer{}
	session.Stdout = stdout
	err = session.Run("hostname")
	if err != nil {
		log.Fatalf("error: %v", err)
	}
	log.Printf("result: %s", stdout.String())
}

sshc.Option

client, err := sshc.NewClient("myhost", User("k1low"), Port(1022))

Available options

  • User
  • Port
  • Passphrase
  • ConfigPath ( Default is ~/.ssh/config and /etc/ssh/ssh_config )
  • UseAgent ( Default is true )

References

About

sshc.NewClient() returns *ssh.Client using ssh_config(5)

License:MIT License


Languages

Language:Go 98.0%Language:Makefile 2.0%