From b279860ebee04c3d660fd9a835e3b9005b5ed20f Mon Sep 17 00:00:00 2001 From: Levi Yan Date: Mon, 28 Oct 2024 18:24:03 +0800 Subject: [PATCH] fix: solve the problem that the private key not works when connecting because permission of private key is too open --- src/user.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/user.ts b/src/user.ts index 905b1c9..25da344 100644 --- a/src/user.ts +++ b/src/user.ts @@ -122,8 +122,10 @@ export default class User { const privateKeyStr = privateKey; try { - fs.writeFileSync(this.getUserPublicKeyPath(), publicKeyStr); - fs.writeFileSync(this.getUserPrivateKeyPath(), privateKeyStr); + await fs.writeFileSync(this.getUserPublicKeyPath(), publicKeyStr); + await fs.writeFileSync(this.getUserPrivateKeyPath(), privateKeyStr); + // limit the permission of private key to prevent that the private key not works + await fs.chmodSync(this.getUserPrivateKeyPath(), 0o600) } catch(error) { console.error("Failed to write public/private key into the default ssh public/key file: ", error); }