easyssh provides a simple wrapper around the standard SSH library. Designed to be like net/http but for ssh.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Justin Judd a842df2410 Added some basic functionality for creating and loading private and public keys. 6 years ago
.gitignore Init commit 7 years ago
LICENSE Init commit 7 years ago
README.md Updated readme with examples 7 years ago
client.go Moved from using logging default logger to a package wide logger that is disabled by default. 6 years ago
common.go Moved from using logging default logger to a package wide logger that is disabled by default. 6 years ago
doc.go Adding current work on easyssh 7 years ago
example_client_test.go Moved from using logging default logger to a package wide logger that is disabled by default. 6 years ago
example_handler_test.go Moved from using logging default logger to a package wide logger that is disabled by default. 6 years ago
example_tcpip_test.go Moved from using logging default logger to a package wide logger that is disabled by default. 6 years ago
example_test.go Moved from using logging default logger to a package wide logger that is disabled by default. 6 years ago
keys.go Added some basic functionality for creating and loading private and public keys. 6 years ago
server.go Moved from using logging default logger to a package wide logger that is disabled by default. 6 years ago
session.go Moved from using logging default logger to a package wide logger that is disabled by default. 6 years ago
tcpip.go Moved from using logging default logger to a package wide logger that is disabled by default. 6 years ago

README.md

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

}