()
| 225 | } |
| 226 | |
| 227 | func ExampleDial() { |
| 228 | var hostKey ssh.PublicKey |
| 229 | // An SSH client is represented with a ClientConn. |
| 230 | // |
| 231 | // To authenticate with the remote server you must pass at least one |
| 232 | // implementation of AuthMethod via the Auth field in ClientConfig, |
| 233 | // and provide a HostKeyCallback. |
| 234 | config := &ssh.ClientConfig{ |
| 235 | User: "username", |
| 236 | Auth: []ssh.AuthMethod{ |
| 237 | ssh.Password("yourpassword"), |
| 238 | }, |
| 239 | HostKeyCallback: ssh.FixedHostKey(hostKey), |
| 240 | } |
| 241 | client, err := ssh.Dial("tcp", "yourserver.com:22", config) |
| 242 | if err != nil { |
| 243 | log.Fatal("Failed to dial: ", err) |
| 244 | } |
| 245 | defer client.Close() |
| 246 | |
| 247 | // Each ClientConn can support multiple interactive sessions, |
| 248 | // represented by a Session. |
| 249 | session, err := client.NewSession() |
| 250 | if err != nil { |
| 251 | log.Fatal("Failed to create session: ", err) |
| 252 | } |
| 253 | defer session.Close() |
| 254 | |
| 255 | // Once a Session is created, you can execute a single command on |
| 256 | // the remote side using the Run method. |
| 257 | var b bytes.Buffer |
| 258 | session.Stdout = &b |
| 259 | if err := session.Run("/usr/bin/whoami"); err != nil { |
| 260 | log.Fatal("Failed to run: " + err.Error()) |
| 261 | } |
| 262 | fmt.Println(b.String()) |
| 263 | } |
| 264 | |
| 265 | func ExamplePublicKeys() { |
| 266 | var hostKey ssh.PublicKey |
nothing calls this directly
no test coverage detected
searching dependent graphs…