From a3114e40d1e378220df4b803254352d32772bb49 Mon Sep 17 00:00:00 2001 From: whyour Date: Wed, 18 May 2022 19:23:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A7=81=E9=92=A5=E6=9D=83?= =?UTF-8?q?=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/sshKey.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/back/services/sshKey.ts b/back/services/sshKey.ts index 91c01c82..16f6b7cc 100644 --- a/back/services/sshKey.ts +++ b/back/services/sshKey.ts @@ -35,7 +35,10 @@ export default class SshKeyService { private generateSshConfig(configs: string[]) { try { for (const config of configs) { - fs.appendFileSync(this.sshConfigFilePath, config, { encoding: 'utf8' }); + fs.appendFileSync(this.sshConfigFilePath, config, { + encoding: 'utf8', + mode: '400', + }); } } catch (error) { this.logger.error('写入ssh配置文件失败', error); @@ -56,6 +59,7 @@ export default class SshKeyService { public addSSHKey(key: string, alias: string, host: string): void { this.generatePrivateKeyFile(alias, key); const config = this.generateSingleSshConfig(alias, host); + this.removeSshConfig(config); this.generateSshConfig([config]); }