summaryrefslogtreecommitdiff
path: root/libgo/go/exp/ssh/doc.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/exp/ssh/doc.go')
-rw-r--r--libgo/go/exp/ssh/doc.go48
1 files changed, 37 insertions, 11 deletions
diff --git a/libgo/go/exp/ssh/doc.go b/libgo/go/exp/ssh/doc.go
index 54a7ba9fdae..fc842b0c1d2 100644
--- a/libgo/go/exp/ssh/doc.go
+++ b/libgo/go/exp/ssh/doc.go
@@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.
/*
-Package ssh implements an SSH server.
+Package ssh implements an SSH client and server.
SSH is a transport security protocol, an authentication protocol and a
family of application protocols. The most typical application level
@@ -11,26 +11,29 @@ protocol is a remote shell and this is specifically implemented. However,
the multiplexed nature of SSH is exposed to users that wish to support
others.
-An SSH server is represented by a Server, which manages a number of
-ServerConnections and handles authentication.
+An SSH server is represented by a ServerConfig, which holds certificate
+details and handles authentication of ServerConns.
- var s Server
- s.PubKeyCallback = pubKeyAuth
- s.PasswordCallback = passwordAuth
+ config := new(ServerConfig)
+ config.PubKeyCallback = pubKeyAuth
+ config.PasswordCallback = passwordAuth
pemBytes, err := ioutil.ReadFile("id_rsa")
if err != nil {
panic("Failed to load private key")
}
- err = s.SetRSAPrivateKey(pemBytes)
+ err = config.SetRSAPrivateKey(pemBytes)
if err != nil {
panic("Failed to parse private key")
}
-Once a Server has been set up, connections can be attached.
+Once a ServerConfig has been configured, connections can be accepted.
- var sConn ServerConnection
- sConn.Server = &s
+ listener := Listen("tcp", "0.0.0.0:2022", config)
+ sConn, err := listener.Accept()
+ if err != nil {
+ panic("failed to accept incoming connection")
+ }
err = sConn.Handshake(conn)
if err != nil {
panic("failed to handshake")
@@ -38,7 +41,6 @@ Once a Server has been set up, connections can be attached.
An SSH connection multiplexes several channels, which must be accepted themselves:
-
for {
channel, err := sConn.Accept()
if err != nil {
@@ -75,5 +77,29 @@ present a simple terminal interface.
}
return
}()
+
+An SSH client is represented with a ClientConn. Currently only the "password"
+authentication method is supported.
+
+ config := &ClientConfig{
+ User: "username",
+ Password: "123456",
+ }
+ client, err := Dial("yourserver.com:22", config)
+
+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 Exec method.
+
+ if err := session.Exec("/usr/bin/whoami"); err != nil {
+ panic("Failed to exec: " + err.String())
+ }
+ reader := bufio.NewReader(session.Stdin)
+ line, _, _ := reader.ReadLine()
+ fmt.Println(line)
+ session.Close()
*/
package ssh