glider-ssh/_examples/ssh-publickey/public_key.go

26 lines
612 B
Go
Raw Normal View History

2016-12-19 19:34:40 +00:00
package main
import (
"fmt"
2016-12-19 19:34:40 +00:00
"io"
"log"
2016-12-19 19:37:23 +00:00
"github.com/gliderlabs/ssh"
gossh "golang.org/x/crypto/ssh"
2016-12-19 19:34:40 +00:00
)
func main() {
ssh.Handle(func(s ssh.Session) {
authorizedKey := gossh.MarshalAuthorizedKey(s.PublicKey())
io.WriteString(s, fmt.Sprintf("public key used by %s:\n", s.User()))
s.Write(authorizedKey)
2016-12-19 19:34:40 +00:00
})
publicKeyOption := ssh.PublicKeyAuth(func(ctx ssh.Context, key ssh.PublicKey) bool {
return true // allow all keys, or use ssh.KeysEqual() to compare against known keys
2016-12-19 19:34:40 +00:00
})
log.Println("starting ssh server on port 2222...")
log.Fatal(ssh.ListenAndServe(":2222", nil, publicKeyOption))
2016-12-19 19:34:40 +00:00
}