Categorygithub.com/k1LoW/sshc/v2
modulepackage
2.4.1
Repository: https://github.com/k1low/sshc.git
Documentation: pkg.go.dev

# README

sshc Build Status GoDoc 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/v2"
)

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 )
  • Knownhosts ( Default is empty )
  • Password

Supported ssh_config keywords

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

References

# Functions

AppendConfigPath returns Option that append ssh_config path to Config.configpaths.
ClearConfigPath returns Option thet clear Config.configpaths,.
ConfigPath is alias of UnshiftConfigPath.
Dial returns *ssh.Client using Config.
Hostname returns Option that set Config.hostname for override SSH client port.
IdentityFile returns Option that set Config.identityKey for override SSH client identity file.
IdentityKey returns Option that set Config.identityKey for override SSH client identity file.
Knownhosts returns Option that override Config.knownhosts.
NewClient reads ssh_config(5) ( Default is ~/.ssh/config and /etc/ssh/ssh_config ) and returns *ssh.Client.
NewConfig creates SSH client config.
Passphrase returns Option that set Config.passphrase for set SSH key passphrase.
Password returns Option that override Config.password.
Port returns Option that set Config.port for override SSH client port.
UnshiftConfigPath returns Option that unshift ssh_config path to Config.configpaths.
UseAgent returns Option that override Config.useAgent.
User returns Option that set Config.user for override SSH client user.

# Structs

Config is the type for the SSH Client config.
No description provided by the author

# Type aliases

Option is the type for change Config.