ssh HostKey added

This commit is contained in:
dalbodeule
2025-10-14 05:35:25 +09:00
parent c0fe02ae51
commit 01677d8865
3 changed files with 160 additions and 10 deletions

32
main.go
View File

@@ -4,13 +4,37 @@ import (
"io"
"log"
"sshchat/utils"
"github.com/gliderlabs/ssh"
)
func main() {
ssh.Handle(func(s ssh.Session) {
io.WriteString(s, "Hello World\n")
})
keys, err := utils.CheckHostKey()
if err != nil {
log.Print("Failed to check SSH keys: generate one.\n", err)
err = utils.GenerateHostKey()
if err != nil {
log.Fatal(err)
}
log.Fatal(ssh.ListenAndServe(":2222", nil))
keys, err = utils.CheckHostKey()
if err != nil {
log.Fatal(err)
}
}
sessionHandler := func(s ssh.Session) {
_, _ = io.WriteString(s, "Hello World\n")
}
s := &ssh.Server{
Addr: ":2222",
Handler: sessionHandler,
}
for _, key := range keys {
s.AddHostKey(key)
}
log.Fatal(s.ListenAndServe())
}