Skip to content
/ sshc Public

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

License

Notifications You must be signed in to change notification settings

k1LoW/sshc

Repository files navigation

sshc Build Status Go Reference Coverage Code to Test Ratio

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/v4"
)

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))

See godoc page

Supported ssh_config keywords

  • Hostname
  • Port
  • User
  • IdentityFile
  • ProxyCommand
  • ProxyJump

References