https://github.com/folbricht/sshtest
Utilities for testing SSH clients in Go
https://github.com/folbricht/sshtest
go golang server ssh testing
Last synced: 2 days ago
JSON representation
Utilities for testing SSH clients in Go
- Host: GitHub
- URL: https://github.com/folbricht/sshtest
- Owner: folbricht
- License: bsd-3-clause
- Created: 2019-03-23T20:55:54.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-23T22:03:13.000Z (over 7 years ago)
- Last Synced: 2026-07-17T14:37:27.540Z (2 days ago)
- Topics: go, golang, server, ssh, testing
- Language: Go
- Size: 6.84 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sshtest
sshtest is a set of utilities for testing SSH features in Go. It currently supports quick setup and start of SSH servers to test a client against. To minimize the need for error handling in tests, most functions panic on error.
## Examples
### Start a simple SSH server with host key
```go
hostKey := sshtest.KeyFromFile("ssh-host-key", "")
server := sshtest.NewServer(hostKey)
defer server.Close()
```
### Start an SSH server with host key and certificate
```go
hostKey := sshtest.KeyFromFile("ssh-host-key", "ssh-host-key-cert.pub")
server := sshtest.NewServer(hostKey)
defer server.Close()
```
### SSH server with custom server config and handler
```go
hostKey := sshtest.KeyFromFile("ssh-host-key", "")
server := sshtest.NewUnstartedServer()
server.Config = &ssh.ServerConfig{NoClientAuth: true}
server.Config.AddHostKey(hostKey)
server.Handler = func(ch ssh.Channel, in <-chan *ssh.Request) {
defer ch.Close()
// Read a request from the client
req, ok := <-in
if !ok {
return
}
fmt.Printf("Received '%s' request from client", req.Type)
// Reply with a string
req.Reply(true, []byte("Hello client"))
// Let the client know the command completed successfuly (status=0)
sshtest.SendStatus(ch, 0)
}
server.Start()
defer server.Close()
```
## Links
- Go SSH library - [https://godoc.org/golang.org/x/crypto/ssh](https://godoc.org/golang.org/x/crypto/ssh)
- GoDoc for sshtest - [https://godoc.org/github.com/folbricht/sshtest](https://godoc.org/github.com/folbricht/sshtest)