easyssh provides a simple wrapper around the standard SSH library. Designed to be like net/http but for ssh.
Go to file
2016-07-30 21:35:10 +09:00
.gitignore Init commit 2015-05-14 22:25:38 +00:00
client.go Moved from using logging default logger to a package wide logger that is disabled by default. 2016-07-30 21:35:10 +09:00
common.go Moved from using logging default logger to a package wide logger that is disabled by default. 2016-07-30 21:35:10 +09:00
doc.go Adding current work on easyssh 2015-05-30 11:19:10 -04:00
example_client_test.go Moved from using logging default logger to a package wide logger that is disabled by default. 2016-07-30 21:35:10 +09:00
example_handler_test.go Moved from using logging default logger to a package wide logger that is disabled by default. 2016-07-30 21:35:10 +09:00
example_tcpip_test.go Moved from using logging default logger to a package wide logger that is disabled by default. 2016-07-30 21:35:10 +09:00
example_test.go Moved from using logging default logger to a package wide logger that is disabled by default. 2016-07-30 21:35:10 +09:00
LICENSE Init commit 2015-05-14 22:25:38 +00:00
README.md Updated readme with examples 2015-05-30 11:19:48 -04:00
server.go Moved from using logging default logger to a package wide logger that is disabled by default. 2016-07-30 21:35:10 +09:00
session.go Moved from using logging default logger to a package wide logger that is disabled by default. 2016-07-30 21:35:10 +09:00
tcpip.go Moved from using logging default logger to a package wide logger that is disabled by default. 2016-07-30 21:35:10 +09:00

easyssh

GoDoc

easyssh provides a simple wrapper around the standard SSH library. Designed to be like net/http but for ssh.

Install

go get dev.justinjudd.org/justin/easyssh

Usage

Server Example

package main

import (
	"fmt"
	"io/ioutil"
	"log"

	"dev.justinjudd.org/justin/easyssh"

	"golang.org/x/crypto/ssh"
)

func main() {

	privateBytes, err := ioutil.ReadFile("id_rsa")
	if err != nil {
		log.Fatal("Failed to load private key (./id_rsa)")
	}

	private, err := ssh.ParsePrivateKey(privateBytes)
	if err != nil {
		log.Fatal("Failed to parse private key")
	}

	config := &ssh.ServerConfig{
		PasswordCallback: func(c ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) {
			if c.User() == "test" && string(pass) == "test" {
				log.Printf("User logged in: %s", c.User())
				return nil, nil
			}
			return nil, fmt.Errorf("password rejected for %s", c.User())
		},
	}
	config.AddHostKey(private)


	easyssh.HandleChannel(easyssh.SessionRequest, easyssh.SessionHandler())
	easyssh.HandleChannel(easyssh.DirectForwardRequest, easyssh.DirectPortForwardHandler())
	easyssh.HandleRequestFunc(easyssh.RemoteForwardRequest, easyssh.TCPIPForwardRequest)

	easyssh.ListenAndServe(":2022", config, nil)
}

Client Example

package main

import (
	"log"

	"dev.justinjudd.org/justin/easyssh"
	"golang.org/x/crypto/ssh"
)

func main() {
	config := &ssh.ClientConfig{
		User: "test",
		Auth: []ssh.AuthMethod{
			ssh.Password("test"),
		},
	}


  conn, err := easyssh.Dial("tcp", "localhost:2022", config)
  if err != nil {
  	log.Fatalf("unable to connect: %s", err)
  }
  defer conn.Close()

  err = conn.LocalForward("localhost:8000", "localhost:6060")
  if err != nil {
  	log.Fatalf("unable to forward local port: %s", err)
  }

}