MCPcopy
hub / github.com/tailscale/tailscale / ExampleDial

Function ExampleDial

tempfork/sshtest/ssh/example_test.go:227–263  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

225}
226
227func 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
265func ExamplePublicKeys() {
266 var hostKey ssh.PublicKey

Callers

nothing calls this directly

Calls 8

CloseMethod · 0.95
RunMethod · 0.95
NewSessionMethod · 0.80
DialMethod · 0.65
FatalMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…