2016-12-19 19:34:40 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
b64 "encoding/base64"
|
|
|
|
|
2016-12-19 19:37:23 +00:00
|
|
|
"github.com/gliderlabs/ssh"
|
2016-12-19 19:34:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
ssh.Handle(func(s ssh.Session) {
|
|
|
|
user := s.User()
|
|
|
|
keyType := s.PublicKey().Type()
|
|
|
|
|
|
|
|
publicKeyString := keyType + " " + b64.StdEncoding.EncodeToString(s.PublicKey().Marshal())
|
|
|
|
|
2017-02-04 21:45:40 +00:00
|
|
|
io.WriteString(s, "Hello "+user+"\n\n")
|
|
|
|
io.WriteString(s, "your public key:\n")
|
|
|
|
io.WriteString(s, publicKeyString+"\n\n")
|
2016-12-19 19:34:40 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
publicKeyHandler := ssh.PublicKeyAuth(func(user string, key ssh.PublicKey) bool {
|
2017-02-04 21:45:40 +00:00
|
|
|
// allow all keys
|
2016-12-19 19:34:40 +00:00
|
|
|
// use ssh.KeysEqual() to compare agains know keys
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
2017-02-04 21:45:40 +00:00
|
|
|
log.Println("starting ssh server on port: 2222")
|
2016-12-19 19:34:40 +00:00
|
|
|
log.Fatal(ssh.ListenAndServe(":2222", nil, publicKeyHandler))
|
|
|
|
}
|