From 8385bcc2d7f2411a07748bb5c53f9eaf4d38d7cc Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Mon, 21 Apr 2025 17:26:42 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20ssh=20PTY=E6=A8=A1=E5=BC=8F=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/plugins/plugin-lib/src/ssh/ssh-access.ts | 11 +++++++++++ packages/plugins/plugin-lib/src/ssh/ssh.ts | 6 ++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/plugins/plugin-lib/src/ssh/ssh-access.ts b/packages/plugins/plugin-lib/src/ssh/ssh-access.ts index 9e4786e3..60c9d90a 100644 --- a/packages/plugins/plugin-lib/src/ssh/ssh-access.ts +++ b/packages/plugins/plugin-lib/src/ssh/ssh-access.ts @@ -63,6 +63,17 @@ export class SshAccess extends BaseAccess { }) passphrase!: string; + @AccessInput({ + title: "伪终端", + helper: "如果登录报错:all authentication methods failed,可以尝试开启伪终端模式进行keyboard-interactive方式登录", + value:false, + component: { + name: "a-switch", + vModel: "checked", + }, + }) + pty = false; + @AccessInput({ title: "socks代理", helper: "socks代理配置,格式:socks5://user:password@host:port", diff --git a/packages/plugins/plugin-lib/src/ssh/ssh.ts b/packages/plugins/plugin-lib/src/ssh/ssh.ts index a86b7464..7000d570 100644 --- a/packages/plugins/plugin-lib/src/ssh/ssh.ts +++ b/packages/plugins/plugin-lib/src/ssh/ssh.ts @@ -170,7 +170,9 @@ export class AsyncSsh2Client { // } return new Promise((resolve, reject) => { this.logger.info(`执行命令:[${this.connConf.host}][exec]: \n` + script); - this.conn.exec(script, { pty: true, env: opts.env }, (err: Error, stream: any) => { + // pty 必须为false, 否则返回值会带上 所有输出,影响返回结果判断, 比如 root#: xxxx + // 当使用keyboard-interactive 登录时,需要pty + this.conn.exec(script, { pty: this.connConf.pty ?? false, env: opts.env }, (err: Error, stream: any) => { if (err) { reject(err); return; @@ -475,7 +477,7 @@ export class SshClient { script = envScripts.join(newLine) + newLine + script; } } - return await conn.exec(script as string, { env: options.env }); + return await conn.exec(script as string, {}); }, }); }