fix: solve the problem that the private key not works when connecting because permission of private key is too open

This commit is contained in:
Levi Yan
2024-10-28 18:24:03 +08:00
parent 98b1ed4a19
commit b279860ebe

View File

@@ -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);
}