Merge pull request #5 from hloeffler/examples

Add Examples
This commit is contained in:
Jeff Lindsay 2016-12-19 13:47:15 -06:00 committed by GitHub
commit d50a1bf50f
2 changed files with 52 additions and 0 deletions

@ -0,0 +1,33 @@
package main
import (
"io"
"log"
b64 "encoding/base64"
"github.com/gliderlabs/ssh"
)
func main() {
ssh.Handle(func(s ssh.Session) {
user := s.User()
keyType := s.PublicKey().Type()
publicKeyString := keyType + " " + b64.StdEncoding.EncodeToString(s.PublicKey().Marshal())
io.WriteString(s, "Hello "+user+"\n")
io.WriteString(s, "your publicKey:\n")
io.WriteString(s, publicKeyString+"\n")
})
publicKeyHandler := ssh.PublicKeyAuth(func(user string, key ssh.PublicKey) bool {
//allow all
// use ssh.KeysEqual() to compare agains know keys
return true
})
log.Fatal(ssh.ListenAndServe(":2222", nil, publicKeyHandler))
}

19
_example/simple/simple.go Normal file

@ -0,0 +1,19 @@
package main
import (
"io"
"log"
"github.com/gliderlabs/ssh"
)
func main() {
ssh.Handle(func(s ssh.Session) {
user := s.User()
io.WriteString(s, "Hello "+user+"\n")
})
log.Fatal(ssh.ListenAndServe(":2222", nil))
}