mirror of
https://github.com/tailscale/tailscale.git
synced 2024-12-04 23:45:34 +00:00
2b8b887d55
(VSCode Live Share between Brad & Maisem!) Updates #3802 Change-Id: Id8edca4481b0811debfdf56d4ccb1a46f71dd6d3 Co-Authored-By: Brad Fitzpatrick <bradfitz@tailscale.com> Signed-off-by: Maisem Ali <maisem@tailscale.com>
51 lines
996 B
Go
51 lines
996 B
Go
package ssh_test
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"io/ioutil"
|
|
|
|
"tailscale.com/tempfork/gliderlabs/ssh"
|
|
)
|
|
|
|
func ExampleListenAndServe() {
|
|
ssh.ListenAndServe(":2222", func(s ssh.Session) {
|
|
io.WriteString(s, "Hello world\n")
|
|
})
|
|
}
|
|
|
|
func ExamplePasswordAuth() {
|
|
ssh.ListenAndServe(":2222", nil,
|
|
ssh.PasswordAuth(func(ctx ssh.Context, pass string) bool {
|
|
return pass == "secret"
|
|
}),
|
|
)
|
|
}
|
|
|
|
func ExampleNoPty() {
|
|
ssh.ListenAndServe(":2222", nil, ssh.NoPty())
|
|
}
|
|
|
|
func ExamplePublicKeyAuth() {
|
|
ssh.ListenAndServe(":2222", nil,
|
|
ssh.PublicKeyAuth(func(ctx ssh.Context, key ssh.PublicKey) error {
|
|
data, err := ioutil.ReadFile("/path/to/allowed/key.pub")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
allowed, _, _, _, err := ssh.ParseAuthorizedKey(data)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !ssh.KeysEqual(key, allowed) {
|
|
return errors.New("some error")
|
|
}
|
|
return nil
|
|
}),
|
|
)
|
|
}
|
|
|
|
func ExampleHostKeyFile() {
|
|
ssh.ListenAndServe(":2222", nil, ssh.HostKeyFile("/path/to/host/key"))
|
|
}
|