Merge pull request #24 from gliderlabs/misc-progrium
fixing a type led to general example cleanup. also added a helpful comment.
This commit is contained in:
commit
a307f226ad
@ -1,33 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
|
||||
b64 "encoding/base64"
|
||||
|
||||
"github.com/gliderlabs/ssh"
|
||||
gossh "golang.org/x/crypto/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\n")
|
||||
io.WriteString(s, "your public key:\n")
|
||||
io.WriteString(s, publicKeyString+"\n\n")
|
||||
authorizedKey := gossh.MarshalAuthorizedKey(s.PublicKey())
|
||||
io.WriteString(s, fmt.Sprintf("public key used by %s:\n", s.User()))
|
||||
s.Write(authorizedKey)
|
||||
})
|
||||
|
||||
publicKeyHandler := ssh.PublicKeyAuth(func(user string, key ssh.PublicKey) bool {
|
||||
// allow all keys
|
||||
// use ssh.KeysEqual() to compare agains know keys
|
||||
return true
|
||||
publicKeyOption := ssh.PublicKeyAuth(func(user string, key ssh.PublicKey) bool {
|
||||
return true // allow all keys, or use ssh.KeysEqual() to compare against known keys
|
||||
})
|
||||
|
||||
log.Println("starting ssh server on port: 2222")
|
||||
log.Fatal(ssh.ListenAndServe(":2222", nil, publicKeyHandler))
|
||||
log.Println("starting ssh server on port 2222...")
|
||||
log.Fatal(ssh.ListenAndServe(":2222", nil, publicKeyOption))
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
|
||||
@ -8,12 +9,10 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
ssh.Handle(func(s ssh.Session) {
|
||||
user := s.User()
|
||||
io.WriteString(s, "Hello "+user+"\n")
|
||||
io.WriteString(s, fmt.Sprintf("Hello %s\n", s.User()))
|
||||
})
|
||||
|
||||
log.Println("starting ssh server on port: 2222")
|
||||
log.Println("starting ssh server on port 2222...")
|
||||
log.Fatal(ssh.ListenAndServe(":2222", nil))
|
||||
}
|
||||
|
@ -59,6 +59,8 @@ func (srv *Server) makeConfig() (*gossh.ServerConfig, error) {
|
||||
if ok := srv.PublicKeyHandler(conn.User(), key); !ok {
|
||||
return perms, fmt.Errorf("permission denied")
|
||||
}
|
||||
// no other way to pass the key from
|
||||
// auth handler to session handler
|
||||
perms.Extensions = map[string]string{
|
||||
"_publickey": string(key.Marshal()),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user