diff --git a/src/sftp.js b/src/sftp.js index ca22eae87..5d7480025 100644 --- a/src/sftp.js +++ b/src/sftp.js @@ -33,6 +33,8 @@ async function ensureKeys() { if (!privateKey || !publicKey) { debug(`ensureSecrets: generating new sftp keys of type ${keyType}`); + safe.fs.unlinkSync(publicKeyFile); + safe.fs.unlinkSync(privateKeyFile); if (!safe.child_process.execSync(`ssh-keygen -m PEM -t ${keyType} -f "${paths.SFTP_KEYS_DIR}/ssh_host_${keyType}_key" -q -N ""`)) throw new BoxError(BoxError.OPENSSL_ERROR, `Could not generate sftp ${keyType} keys: ${safe.error.message}`); const newPublicKey = safe.fs.readFileSync(publicKeyFile); await blobs.set(`sftp_${keyType}_public_key`, newPublicKey);