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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
b64 "encoding/base64"
|
|
||||||
|
|
||||||
"github.com/gliderlabs/ssh"
|
"github.com/gliderlabs/ssh"
|
||||||
|
gossh "golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
ssh.Handle(func(s ssh.Session) {
|
ssh.Handle(func(s ssh.Session) {
|
||||||
user := s.User()
|
authorizedKey := gossh.MarshalAuthorizedKey(s.PublicKey())
|
||||||
keyType := s.PublicKey().Type()
|
io.WriteString(s, fmt.Sprintf("public key used by %s:\n", s.User()))
|
||||||
|
s.Write(authorizedKey)
|
||||||
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")
|
|
||||||
})
|
})
|
||||||
|
|
||||||
publicKeyHandler := ssh.PublicKeyAuth(func(user string, key ssh.PublicKey) bool {
|
publicKeyOption := ssh.PublicKeyAuth(func(user string, key ssh.PublicKey) bool {
|
||||||
// allow all keys
|
return true // allow all keys, or use ssh.KeysEqual() to compare against known keys
|
||||||
// use ssh.KeysEqual() to compare agains know keys
|
|
||||||
return true
|
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Println("starting ssh server on port: 2222")
|
log.Println("starting ssh server on port 2222...")
|
||||||
log.Fatal(ssh.ListenAndServe(":2222", nil, publicKeyHandler))
|
log.Fatal(ssh.ListenAndServe(":2222", nil, publicKeyOption))
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
@ -8,12 +9,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
ssh.Handle(func(s ssh.Session) {
|
ssh.Handle(func(s ssh.Session) {
|
||||||
user := s.User()
|
io.WriteString(s, fmt.Sprintf("Hello %s\n", s.User()))
|
||||||
io.WriteString(s, "Hello "+user+"\n")
|
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Println("starting ssh server on port: 2222")
|
log.Println("starting ssh server on port 2222...")
|
||||||
log.Fatal(ssh.ListenAndServe(":2222", nil))
|
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 {
|
if ok := srv.PublicKeyHandler(conn.User(), key); !ok {
|
||||||
return perms, fmt.Errorf("permission denied")
|
return perms, fmt.Errorf("permission denied")
|
||||||
}
|
}
|
||||||
|
// no other way to pass the key from
|
||||||
|
// auth handler to session handler
|
||||||
perms.Extensions = map[string]string{
|
perms.Extensions = map[string]string{
|
||||||
"_publickey": string(key.Marshal()),
|
"_publickey": string(key.Marshal()),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user