NewClientConfig returns a client config that can only connect to a loopback address.
(fs afero.Fs, user string, privateKeyPath string)
| 48 | |
| 49 | // NewClientConfig returns a client config that can only connect to a loopback address. |
| 50 | func NewClientConfig(fs afero.Fs, user string, privateKeyPath string) (*ssh.ClientConfig, error) { |
| 51 | fileBytes, err := afero.ReadFile(fs, privateKeyPath) |
| 52 | if err != nil { |
| 53 | return nil, fmt.Errorf("failed to open private key file: %w", err) |
| 54 | } |
| 55 | signer, err := ssh.ParsePrivateKey(fileBytes) |
| 56 | if err != nil { |
| 57 | return nil, fmt.Errorf("failed to parse private key from %s: %w", privateKeyPath, err) |
| 58 | } |
| 59 | |
| 60 | auths := []ssh.AuthMethod{ssh.PublicKeys(signer)} |
| 61 | |
| 62 | return &ssh.ClientConfig{ |
| 63 | User: user, |
| 64 | Auth: auths, |
| 65 | HostKeyCallback: hostKeyCallback(), |
| 66 | }, nil |
| 67 | } |