From 1d2df860e8e11516ff342085c4330c46acdd6f38 Mon Sep 17 00:00:00 2001 From: whyour Date: Thu, 6 Apr 2023 14:23:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20ssh=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/sshKey.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/back/services/sshKey.ts b/back/services/sshKey.ts index d3f16e5b..03df8723 100644 --- a/back/services/sshKey.ts +++ b/back/services/sshKey.ts @@ -12,7 +12,7 @@ export default class SshKeyService { private homedir = os.homedir(); private sshPath = config.sshdPath; private sshConfigFilePath = path.resolve(this.homedir, '.ssh', 'config'); - private sshConfigHeader = `Include ${this.sshPath}*.config`; + private sshConfigHeader = `Include ${path.join(this.sshPath, '*.config')}`; constructor(@Inject('logger') private logger: winston.Logger) { this.initSshConfigFile() @@ -27,7 +27,7 @@ export default class SshKeyService { private generatePrivateKeyFile(alias: string, key: string): void { try { - fs.writeFileSync(`${this.sshPath}/${alias}`, `${key}${os.EOL}`, { + fs.writeFileSync(path.join(this.sshPath, alias), `${key}${os.EOL}`, { encoding: 'utf8', mode: '400', }); @@ -56,8 +56,8 @@ export default class SshKeyService { host = `ssh.github.com\n Port 443\n HostkeyAlgorithms +ssh-rsa\n PubkeyAcceptedAlgorithms +ssh-rsa`; } const proxyStr = proxy ? ` ProxyCommand nc -v -x ${proxy} %h %p\n` : ''; - const config = `Host ${alias}\n Hostname ${host}\n IdentityFile ${this.sshPath}/${alias}\n StrictHostKeyChecking no\n${proxyStr}`; - fs.writeFileSync(`${this.sshPath}/${alias}.config`, config, { encoding: 'utf8' }); + const config = `Host ${alias}\n Hostname ${host}\n IdentityFile ${path.join(this.sshPath, alias)}\n StrictHostKeyChecking no\n${proxyStr}`; + fs.writeFileSync(`${path.join(this.sshPath, `${alias}.config`)}`, config, { encoding: 'utf8' }); } private removeSshConfig(alias: string) {