ReadPrivateKey attempts to read an SSH private key from path and returns an ssh.Signer.
(path string)
| 173 | // ReadPrivateKey attempts to read an SSH private key from path |
| 174 | // and returns an ssh.Signer. |
| 175 | func ReadPrivateKey(path string) (gossh.Signer, error) { |
| 176 | f, err := os.Open(path) |
| 177 | if err != nil { |
| 178 | return nil, fmt.Errorf("open private key file: %w", err) |
| 179 | } |
| 180 | defer f.Close() |
| 181 | bs, err := io.ReadAll(f) |
| 182 | if err != nil { |
| 183 | return nil, fmt.Errorf("read private key file: %w", err) |
| 184 | } |
| 185 | k, err := gossh.ParsePrivateKey(bs) |
| 186 | if err != nil { |
| 187 | return nil, fmt.Errorf("parse private key file: %w", err) |
| 188 | } |
| 189 | return k, nil |
| 190 | } |
| 191 | |
| 192 | // DecodeBase64PrivateKey attempts to decode a base64 encoded private |
| 193 | // key and returns an ssh.Signer |