returns ssh.Signer from user you running app home path + cutted key path. (ex. pubkey,err := getKeyFile("/.ssh/id_rsa") )
(keypath, passphrase string)
| 116 | // returns ssh.Signer from user you running app home path + cutted key path. |
| 117 | // (ex. pubkey,err := getKeyFile("/.ssh/id_rsa") ) |
| 118 | func getKeyFile(keypath, passphrase string) (ssh.Signer, error) { |
| 119 | var pubkey ssh.Signer |
| 120 | var err error |
| 121 | buf, err := os.ReadFile(keypath) |
| 122 | if err != nil { |
| 123 | return nil, err |
| 124 | } |
| 125 | |
| 126 | if passphrase != "" { |
| 127 | pubkey, err = sshkeys.ParseEncryptedPrivateKey(buf, []byte(passphrase)) |
| 128 | } else { |
| 129 | pubkey, err = ssh.ParsePrivateKey(buf) |
| 130 | } |
| 131 | |
| 132 | if err != nil { |
| 133 | return nil, err |
| 134 | } |
| 135 | |
| 136 | return pubkey, nil |
| 137 | } |
| 138 | |
| 139 | // returns *ssh.ClientConfig and io.Closer. |
| 140 | // if io.Closer is not nil, io.Closer.Close() should be called when |
no outgoing calls