| 93 | } |
| 94 | |
| 95 | func newSSHConfig(user, keyFile string) (*ssh.ClientConfig, error) { |
| 96 | keyData, err := os.ReadFile(keyFile) |
| 97 | if err != nil { |
| 98 | return nil, fmt.Errorf("%w: failed to read private key (%w) — this is usually a file-permission or antivirus issue; "+ |
| 99 | "delete that file and reconnect, or check that your security software isn't blocking the .thunder folder", ErrKeyUnreadable, err) |
| 100 | } |
| 101 | |
| 102 | signer, err := ssh.ParsePrivateKey(keyData) |
| 103 | if err != nil { |
| 104 | return nil, fmt.Errorf("failed to parse private key: %w", err) |
| 105 | } |
| 106 | |
| 107 | return &ssh.ClientConfig{ |
| 108 | User: user, |
| 109 | Auth: []ssh.AuthMethod{ |
| 110 | ssh.PublicKeys(signer), |
| 111 | }, |
| 112 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), |
| 113 | Timeout: 10 * time.Second, |
| 114 | }, nil |
| 115 | } |
| 116 | |
| 117 | func RobustSSHConnect(ip, keyFile string, port int, maxWait int) (*SSHClient, error) { |
| 118 | return RobustSSHConnectCtx(context.Background(), ip, keyFile, port, maxWait) |