sshc

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2021 License: MIT Imports: 22 Imported by: 1

README

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

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 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(host string, options ...Option) (*Config, error)

NewConfig creates SSH client config.

func (*Config) DialWithConfig

func (c *Config) DialWithConfig() (*ssh.Client, error)

DialWithConfig returns *ssh.Client using Config

func (*Config) Get

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

Get returns Config value.

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 ClearConfigPath

func ClearConfigPath() Option

ClearConfigPath returns Option thet clear Config.configpaths,

func ConfigPath

func ConfigPath(p string) Option

ConfigPath is alias of UnshiftConfigPath.

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