fix: generate key pair hangs when key files already exist (#590)

ssh-keygen prompts 'Overwrite (y/n)?' on stdout when the target file
exists. With stdio: ['pipe','pipe','pipe'] nothing is written to stdin,
so the process blocks indefinitely.

Delete both the private key and its .pub counterpart before spawning
ssh-keygen so the overwrite prompt is never triggered.
This commit is contained in:
MickLesk
2026-05-27 13:32:07 +02:00
parent f650b91a2e
commit 31e037e43c

View File

@@ -662,7 +662,14 @@ expect {
async generateKeyPair(serverId) {
const sshKeysDir = join(process.cwd(), 'data', 'ssh-keys');
const keyPath = join(sshKeysDir, `server_${serverId}_key`);
const keyPubPath = keyPath + '.pub';
// Remove existing key files so ssh-keygen does not prompt "Overwrite (y/n)?"
// which would block stdin indefinitely.
for (const p of [keyPath, keyPubPath]) {
try { unlinkSync(p); } catch { /* file didn't exist that's fine */ }
}
return new Promise((resolve, reject) => {
const sshKeygen = spawn('ssh-keygen', [
'-t', 'ed25519',