diff --git a/src/storage/filesystem.js b/src/storage/filesystem.js index d8a11781a..172d0c428 100644 --- a/src/storage/filesystem.js +++ b/src/storage/filesystem.js @@ -270,11 +270,14 @@ async function removeDir(config, limits, remotePathPrefix, progressCallback) { progressCallback({ message: `Removing directory ${fullPathPrefix}` }); if (config._provider === mounts.MOUNT_TYPE_SSHFS) { - const identityFilePath = path.join(paths.SSHFS_KEYS_DIR, `identity_file_${path.basename(config._managedMountPath)}`); + // we use a temporary key file instead of passing it as stdin + const identityFilePath = `/tmp/identity_file_${config._managedMountPath.replaceAll('/', '-')}`; + if (!safe.fs.writeFileSync(identityFilePath, `${config.mountOptions.privateKey}\n`, { mode: 0o600 })) throw new BoxError(BoxError.FS_ERROR, `Could not write temporary private key: ${safe.error.message}`); const sshOptions = [ '-o', '"StrictHostKeyChecking no"', '-i', identityFilePath, '-p', config.mountOptions.port, `${config.mountOptions.user}@${config.mountOptions.host}` ]; const sshArgs = sshOptions.concat([ 'rm', '-rf', path.join(config.prefix ?? '', remotePathPrefix) ]); const [remoteRmError] = await safe(shell.spawn('ssh', sshArgs, { shell: true })); + safe.fs.unlinkSync(identityFilePath); if (!remoteRmError) return; if (remoteRmError.code === 255) throw new BoxError(BoxError.EXTERNAL_ERROR, `SSH connection error: ${remoteRmError.message}`); // do not attempt fallback copy for ssh errors debug('SSH remote rm failed, trying sshfs rm'); // this can happen for sshfs mounted windows server