diff options
Diffstat (limited to 'libgo/go/exp/ssh/doc.go')
-rw-r--r-- | libgo/go/exp/ssh/doc.go | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/libgo/go/exp/ssh/doc.go b/libgo/go/exp/ssh/doc.go index 480f877..e7deb5e 100644 --- a/libgo/go/exp/ssh/doc.go +++ b/libgo/go/exp/ssh/doc.go @@ -14,7 +14,7 @@ others. An SSH server is represented by a ServerConfig, which holds certificate details and handles authentication of ServerConns. - config := new(ServerConfig) + config := new(ssh.ServerConfig) config.PubKeyCallback = pubKeyAuth config.PasswordCallback = passwordAuth @@ -34,8 +34,7 @@ Once a ServerConfig has been configured, connections can be accepted. if err != nil { panic("failed to accept incoming connection") } - err = sConn.Handshake(conn) - if err != nil { + if err := sConn.Handshake(conn); err != nil { panic("failed to handshake") } @@ -60,16 +59,20 @@ the case of a shell, the type is "session" and ServerShell may be used to present a simple terminal interface. if channel.ChannelType() != "session" { - c.Reject(UnknownChannelType, "unknown channel type") + channel.Reject(UnknownChannelType, "unknown channel type") return } channel.Accept() - shell := NewServerShell(channel, "> ") + term := terminal.NewTerminal(channel, "> ") + serverTerm := &ssh.ServerTerminal{ + Term: term, + Channel: channel, + } go func() { defer channel.Close() for { - line, err := shell.ReadLine() + line, err := serverTerm.ReadLine() if err != nil { break } @@ -78,8 +81,27 @@ present a simple terminal interface. return }() +To authenticate with the remote server you must pass at least one implementation of +ClientAuth via the Auth field in ClientConfig. + + // password implements the ClientPassword interface + type password string + + func (p password) Password(user string) (string, error) { + return string(p), nil + } + + config := &ssh.ClientConfig { + User: "username", + Auth: []ClientAuth { + // ClientAuthPassword wraps a ClientPassword implementation + // in a type that implements ClientAuth. + ClientAuthPassword(password("yourpassword")), + } + } + An SSH client is represented with a ClientConn. Currently only the "password" -authentication method is supported. +authentication method is supported. config := &ClientConfig{ User: "username", @@ -87,19 +109,19 @@ authentication method is supported. } client, err := Dial("yourserver.com:22", config) -Each ClientConn can support multiple interactive sessions, represented by a Session. +Each ClientConn can support multiple interactive sessions, represented by a Session. session, err := client.NewSession() -Once a Session is created, you can execute a single command on the remote side -using the Run method. +Once a Session is created, you can execute a single command on the remote side +using the Exec method. + b := bytes.NewBuffer() + session.Stdin = b if err := session.Run("/usr/bin/whoami"); err != nil { panic("Failed to exec: " + err.String()) } - reader := bufio.NewReader(session.Stdin) - line, _, _ := reader.ReadLine() - fmt.Println(line) + fmt.Println(bytes.String()) session.Close() */ package ssh |