Source File
doc.go
Belonging Package
github.com/gliderlabs/ssh
/*Package ssh wraps the crypto/ssh package with a higher-level API for buildingSSH servers. The goal of the API was to make it as simple as using net/http, sothe API is very similar.You should be able to build any SSH server using only this package, which wrapsrelevant types and some functions from crypto/ssh. However, you still need touse crypto/ssh for building SSH clients.ListenAndServe starts an SSH server with a given address, handler, and options. Thehandler is usually nil, which means to use DefaultHandler. Handle sets DefaultHandler:ssh.Handle(func(s ssh.Session) {io.WriteString(s, "Hello world\n")})log.Fatal(ssh.ListenAndServe(":2222", nil))If you don't specify a host key, it will generate one every time. This is convenientexcept you'll have to deal with clients being confused that the host key is different.It's a better idea to generate or point to an existing key on your system:log.Fatal(ssh.ListenAndServe(":2222", nil, ssh.HostKeyFile("/Users/progrium/.ssh/id_rsa")))Although all options have functional option helpers, another way to control theserver's behavior is by creating a custom Server:s := &ssh.Server{Addr: ":2222",Handler: sessionHandler,PublicKeyHandler: authHandler,}s.AddHostKey(hostKeySigner)log.Fatal(s.ListenAndServe())This package automatically handles basic SSH requests like setting environmentvariables, requesting PTY, and changing window size. These requests areprocessed, responded to, and any relevant state is updated. This state is thenexposed to you via the Session interface.The one big feature missing from the Session abstraction is signals. This wasstarted, but not completed. Pull Requests welcome!*/package ssh
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |