/
main.go
33 lines (27 loc) · 835 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"context"
"log"
"github.com/fango6/sshd"
"golang.org/x/crypto/ssh"
)
func main() {
mux := sshd.NewServeMux()
mux.HandleFunc("session", func(ctx context.Context, conn *ssh.ServerConn, newChannel ssh.NewChannel) error {
log.Printf("recv %s connection\n", conn.RemoteAddr())
return conn.Close()
})
sshd.PublicKeyAuth(func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
fingerprint := ssh.FingerprintSHA256(key)
log.Printf("remote %s@%s, fingerprint %s", conn.User(), conn.RemoteAddr(), fingerprint)
return &ssh.Permissions{
Extensions: map[string]string{
"fingerprint": fingerprint,
},
}, nil
})
if err := sshd.ListenAndServe(":56789", sshd.GetDefaultSshServerConfig, mux); err != nil {
log.Println("serve error:", err)
}
log.Println("sshd exited")
}