ssh

package
v0.0.0-...-5613f3b Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2020 License: Apache-2.0 Imports: 17 Imported by: 1

Documentation

Overview

Package ssh provides a GOlang library for copying files and running commands over SSH

## Example ```go package main

import (

"github.com/appscode/go/crypto/ssh"
"log"
"os"

)

func main() {
	signer, err := ssh.MakePrivateKeySignerFromFile(os.ExpandEnv("$HOME/.ssh/id_rsa"))
	if err != nil {
		log.Fatal(err)
	}
	sout, serr, code, err := sshtools.Exec("ls -l /", "root", "<addr>:<port>", signer)
	log.Println(sout, serr, code, err)
}

```

## Acknowledgement This library is based on code from:

Index

Constants

View Source
const RSABitSize = 2048

Variables

This section is empty.

Functions

func EncodePrivateKey

func EncodePrivateKey(private *rsa.PrivateKey) []byte

func EncodePublicKey

func EncodePublicKey(public *rsa.PublicKey) ([]byte, error)

func EncodeSSHKey

func EncodeSSHKey(public *rsa.PublicKey) ([]byte, error)

func Exec

func Exec(cmd, user, host string, signer ssh.Signer) (string, string, int, error)

RunSSHCommand returns the stdout, stderr, and exit code from running cmd on host as specific user, along with any SSH-level error. If user=="", it will default (like SSH) to os.Getenv("USER")

func GenerateKey

func GenerateKey(bits int) (*rsa.PrivateKey, *rsa.PublicKey, error)

func MakePrivateKeySignerFromBytes

func MakePrivateKeySignerFromBytes(buffer []byte) (ssh.Signer, error)

func MakePrivateKeySignerFromFile

func MakePrivateKeySignerFromFile(key string) (ssh.Signer, error)

func ParsePublicKeyFromFile

func ParsePublicKeyFromFile(keyFile string) (*rsa.PublicKey, error)

func SCP

func SCP(dst string, contents []byte, user, host string, signer ssh.Signer) (string, string, int, error)

UploadFile returns the stdout, stderr, and exit code from creating a destination file on host as specific user, along with any SSH-level error. If user=="", it will default (like SSH) to os.Getenv("USER")

Types

type Client

type Client struct {
	*ssh.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(user, host string, signer ssh.Signer) (*Client, error)

Internal implementation of runSSHCommand, for testing

func (*Client) Exec

func (c *Client) Exec(cmd string) (string, string, int, error)

Internal implementation of runSSHCommand, for testing

func (*Client) SCP

func (c *Client) SCP(dst string, contents []byte) (string, string, int, error)

Internal implementation of runSSHCommand, for testing

type SSHKey

type SSHKey struct {
	PublicKey          []byte `json:"publicKey,omitempty"`
	PrivateKey         []byte `json:"privateKey,omitempty"`
	AwsFingerprint     string `json:"awsFingerprint,omitempty"`
	OpensshFingerprint string `json:"opensshFingerprint,omitempty"`
}

func NewSSHKeyPair

func NewSSHKeyPair() (*SSHKey, error)

Source: https://github.com/flynn/flynn/blob/master/pkg/sshkeygen/sshkeygen.go This generates a single RSA 2048-bit SSH key AWS Key pair: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#verify-key-pair-fingerprints https://forums.aws.amazon.com/thread.jspa?messageID=386670&tstart=0

From PUB key: ssh-keygen -f ~/.ssh/id_rsa.pub -e -m PKCS8 | openssl pkey -pubin -outform DER | openssl md5 -c From PRIV key: openssl rsa -in ~/.ssh/id_rsa -pubout -outform DER | openssl md5 -c

func ParseSSHKeyPair

func ParseSSHKeyPair(pub, priv string) (*SSHKey, error)

Jump to

Keyboard shortcuts

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