sshc

package module
v3.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2023 License: MIT Imports: 18 Imported by: 2

README

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

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

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dial

func Dial(dc *DialConfig) (*ssh.Client, error)

Dial returns *ssh.Client using Config

func NewClient

func NewClient(host string, options ...Option) (*ssh.Client, error)

NewClient reads ssh_config(5) ( Default is ~/.ssh/config and /etc/ssh/ssh_config ) and returns *ssh.Client.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config is the type for the SSH Client config. not ssh_config.

func NewConfig

func NewConfig(options ...Option) (*Config, error)

NewConfig creates SSH client config.

func (*Config) Get

func (c *Config) Get(host, key string) string

Get returns Config value.

type DialConfig

type DialConfig struct {
	Hostname     string
	User         string
	Port         int
	Passphrase   []byte
	UseAgent     bool
	Knownhosts   []string
	IdentityKey  []byte
	ProxyCommand string
	ProxyJump    string
	Password     string
	Timeout      time.Duration
	Wd           string
	Auth         []ssh.AuthMethod
}

type Option

type Option func(*Config) error

Option is the type for change Config.

func AppendConfigPath

func AppendConfigPath(p string) Option

AppendConfigPath returns Option that append ssh_config path to Config.configpaths.

func AuthMethod added in v3.1.0

func AuthMethod(m ssh.AuthMethod) Option

AuthMethod returns Option that append ssh.AuthMethod to Config.auth

func ClearConfigPath

func ClearConfigPath() Option

ClearConfigPath returns Option thet clear Config.configpaths,

func ConfigPath

func ConfigPath(p string) Option

ConfigPath is alias of UnshiftConfigPath.

func Hostname

func Hostname(h string) Option

Hostname returns Option that set Config.hostname for override SSH client port.

func IdentityFile

func IdentityFile(p string) Option

IdentityFile returns Option that set Config.identityKey for override SSH client identity file.

func IdentityKey

func IdentityKey(b []byte) Option

IdentityKey returns Option that set Config.identityKey for override SSH client identity file.

func Knownhosts

func Knownhosts(files ...string) Option

Knownhosts returns Option that override Config.knownhosts.

func Passphrase

func Passphrase(p []byte) Option

Passphrase returns Option that set Config.passphrase for set SSH key passphrase.

func Password

func Password(pass string) Option

Password returns Option that override Config.password

func Port

func Port(p int) Option

Port returns Option that set Config.port for override SSH client port.

func UnshiftConfigPath

func UnshiftConfigPath(p string) Option

UnshiftConfigPath returns Option that unshift ssh_config path to Config.configpaths.

func UseAgent

func UseAgent(u bool) Option

UseAgent returns Option that override Config.useAgent.

func User

func User(u string) Option

User returns Option that set Config.user for override SSH client user.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL