commit
d50a1bf50f
33
_example/public_key/public_key.go
Normal file
33
_example/public_key/public_key.go
Normal file
@ -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
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))
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user