Skip to content
Snippets Groups Projects
user avatar
dependabot[bot] authored
Bumps [golang.org/x/term](https://github.com/golang/term) from 0.26.0 to 0.27.0.
- [Commits](https://github.com/golang/term/compare/v0.26.0...v0.27.0

)

---
updated-dependencies:
- dependency-name: golang.org/x/term
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: default avatardependabot[bot] <support@github.com>
e5e1c693
History

sshutil

A single-dependency utility package that provides a net/http style SSH server.

sshutil is part of the Smallstep crypto suite (step, step-ca, etc.).

Why sshutil?

The sshutil package depends solely on the Go x/crypto module. The x/crypto/ssh package provides convenient support for the ssh wire protocol, the ssh authentication protocol, and the ssh connection protocol. SSH, and thus the x/crypto implementation, is natually scoped to a single connection—whereas servers generally need to accept many connections. A small, but tedious, amount of work is required to implement a full connection-tracking server for use in applications. sshutil fills in the gap.

Get

$ go get go.step.sm/sshutil

Examples

Example can be found in the examples directory. Run with:

$ go run go.step.sm/example/<name>
$ go run ./example/<name>

Hello SSH

hello

package main

import "go.step.sm/sshutil"

func() hello(stream sshutil.Session) {
	stream.Terminal.Write([]byte("Hello SSH\n")
}

func main() {
	server := &sshutil.Server{Addr: ":2022"}
	server.Channel("session", sshutil.NewSessionHandler(hello))
	server.ListenAndServe()
}

Output:

$ go run ./example/hello
$ ssh localhost -p 2022
Hello SSH
Server closed remote connection to localhost.

Host Key

Easily configure a persistent host key using sshutil.LoadHostKeyFromFile. The default session handler is an echo terminal server.

hostkey

package main

import (
	"log"

	"go.step.sm/sshutil"
)

func main() {
	server := &sshutil.Server{
		Addr: ":2022",
		Config: sshutil.DefaultServerConfig(),
	}

	key, err := sshutil.LoadHostKeyFromFile("example/server.key", "")
	if err != nil {
		log.Fatalf("error loading key: %v", err)
	}
	server.Config.AddHostKey(key)

	err = server.ListenAndServe()
	log.Print(err)
}

Output:

$ go run ./example/hostkey
$ ssh localhost -p 2022
> echo
echo
> ^D
Client closed connection to localhost.

Test

$ go test