MCPcopy Index your code
hub / github.com/tailscale/tailscale / ExamplePublicKeys

Function ExamplePublicKeys

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

Source from the content-addressed store, hash-verified

263}
264
265func ExamplePublicKeys() {
266 var hostKey ssh.PublicKey
267 // A public key may be used to authenticate against the remote
268 // server by using an unencrypted PEM-encoded private key file.
269 //
270 // If you have an encrypted private key, the crypto/x509 package
271 // can be used to decrypt it.
272 key, err := os.ReadFile("/home/user/.ssh/id_rsa")
273 if err != nil {
274 log.Fatalf("unable to read private key: %v", err)
275 }
276
277 // Create the Signer for this private key.
278 signer, err := ssh.ParsePrivateKey(key)
279 if err != nil {
280 log.Fatalf("unable to parse private key: %v", err)
281 }
282
283 config := &ssh.ClientConfig{
284 User: "user",
285 Auth: []ssh.AuthMethod{
286 // Use the PublicKeys method for remote authentication.
287 ssh.PublicKeys(signer),
288 },
289 HostKeyCallback: ssh.FixedHostKey(hostKey),
290 }
291
292 // Connect to the remote server and perform the SSH handshake.
293 client, err := ssh.Dial("tcp", "host.com:22", config)
294 if err != nil {
295 log.Fatalf("unable to connect: %v", err)
296 }
297 defer client.Close()
298}
299
300func ExampleClient_Listen() {
301 var hostKey ssh.PublicKey

Callers

nothing calls this directly

Calls 4

ReadFileMethod · 0.65
FatalfMethod · 0.65
DialMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…