MCPcopy Index your code
hub / github.com/linuxkit/linuxkit / getSSHAuth

Function getSSHAuth

src/cmd/linuxkit/scaleway.go:275–302  ·  view source on GitHub ↗

getSSHAuth gets the ssh.Signer needed to connect via SSH

(sshKeyPath string)

Source from the content-addressed store, hash-verified

273
274// getSSHAuth gets the ssh.Signer needed to connect via SSH
275func getSSHAuth(sshKeyPath string) (ssh.Signer, error) {
276 f, err := os.Open(sshKeyPath)
277 if err != nil {
278 return nil, err
279 }
280 defer func() { _ = f.Close() }()
281
282 buf, err := io.ReadAll(f)
283 if err != nil {
284 return nil, err
285 }
286 signer, err := ssh.ParsePrivateKey(buf)
287 if err != nil {
288 fmt.Print("Enter ssh key passphrase: ")
289 bytePassword, err := term.ReadPassword(int(syscall.Stdin))
290 // ReadPassword eats newline, put it back to avoid mangling logs
291 fmt.Println()
292 if err != nil {
293 return nil, err
294 }
295 signer, err := sshkeys.ParseEncryptedPrivateKey(buf, bytePassword)
296 if err != nil {
297 return nil, err
298 }
299 return signer, nil
300 }
301 return signer, err
302}
303
304// CopyImageToInstance copies the image to the instance via ssh
305func (s *ScalewayClient) CopyImageToInstance(instanceID, path, sshKeyPath string) error {

Callers 1

CopyImageToInstanceMethod · 0.85

Calls 2

OpenMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected