-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (37 loc) · 896 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"net"
"os"
log "github.com/Sirupsen/logrus"
"golang.org/x/crypto/ssh"
)
func main() {
log.SetOutput(os.Stderr)
config := &ssh.ServerConfig{
KeyboardInteractiveCallback: keyboardInteractiveCallback,
PublicKeyCallback: publicKeyCallback,
}
loadBlacklistedKeys()
private, err := ssh.ParsePrivateKey([]byte(os.Getenv("HOST_PRIVATE_KEY")))
if err != nil {
log.Fatalln("Failed to parse host private key")
}
config.AddHostKey(private)
addr := os.Getenv("ADDR")
if addr == "" {
addr = "localhost:2022"
}
listener, err := net.Listen("tcp", addr)
if err != nil {
log.Fatalf("Failed to listen for connection on %s, perhaps that port is already in use", addr)
}
log.Infoln("Listening on", addr)
for {
conn, err := listener.Accept()
if err != nil {
log.Warnln("Accept failed:", err)
continue
}
go serve(config, conn)
}
}