how can i input the password use keyboard-interactive

未关闭
#385 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞

调研方向

使用提供的 node-ssh 连接选项复现该故障,然后阅读 node-ssh 的身份验证处理以及其捆绑的 ssh2 客户端流程。将文档中 onKeyboardInteractive 和 tryKeyboard 的行为与 authHandler 示例进行比较。完成的标准是能够到达 keyboard-interactive 回调,并且密码重试在不出现客户端身份验证错误的情况下完成。

由索引模型根据 Issue 内容生成。

描述

env

i want to connet to the different host, some of them no config the no password login,so i need to try to connect the host no password firstly, if faild ,i'll use prompts ask the user to input the password to retry.

ssh2

when i use ssh2 to achieve it, the code like this:

conn.on('ready', () => {
 // some code
}).connect({
    host,
    port: 22,
    username,
    tryKeyboard: true,
    authHandler: (methodsLeft, partialSuccess, callback) => {
      prompts([{
        type: 'password',
        name: 'newPassword',
        message: `input the password of ${hostItem}:`,
      }]).then(({newPassword}) => {
        callback({type: 'password', username, password: newPassword})
      })
    },
 })

the code workd very well

node-ssh

the ssh2 hard to exec the multiple command on one connect. but the node-ssh is easy to do that.
when i try to connect , the problem was happen,

 Error: All configured authentication methods failed
    at doNextAuth (E:\workSpace\my-project-name\node_modules\node-ssh\node_modules\ssh2\lib\client.js:413:17)
    at tryNextAuth (E:\workSpace\my-project-name\node_modules\node-ssh\node_modules\ssh2\lib\client.js:484:5)
    at SSH2Stream.onUSERAUTH_FAILURE (E:\workSpace\my-project-name\node_modules\node-ssh\node_modules\ssh2\lib\client.js:597:5)
    at SSH2Stream.emit (events.js:310:20)
    at parsePacket (E:\workSpace\my-project-name\node_modules\ssh2-streams\lib\ssh.js:3682:10)
    at SSH2Stream._transform (E:\workSpace\my-project-name\node_modules\ssh2-streams\lib\ssh.js:701:13)
    at SSH2Stream.Transform._read (_stream_transform.js:191:10)
    at SSH2Stream._read (E:\workSpace\my-project-name\node_modules\ssh2-streams\lib\ssh.js:253:15)
    at SSH2Stream.Transform._write (_stream_transform.js:179:12)
    at doWrite (_stream_writable.js:442:12) {
  level: 'client-authentication'
}

from other issus i knew the authHandler not support so i tyied the onKeyboardInteractive, but obviously,it not be called ,because i can't see the console mark.
my code are following:

ssh.connect({
    host,
    username,
    port: 22,
    tryKeyboard: true,
    debug: console.log(),
    onKeyboardInteractive(name, instructions, instructionsLang, prompts, finish) {
      console.log('🔊🚀🚀🚀🔊 ~ RollbackCommand ~', prompts)
      if (prompts.length > 0 && prompts[0].prompt.toLowerCase().includes('password')) {
        prompts([{
          type: 'password',
          name: 'newPassword',
          message: `input the password of ${hostItem}:`,
        }]).then(({newPassword}) => {
          finish([newPassword])
        })
      }
    },
    })

i'm a newcoming ,so i'm not sure it's my code error or i use this API in wrong way.
i need some help, thx

主要语言
TypeScript
星标
1k
派生
94
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

steelbrain/node-ssh 的其他 Issue

查看 steelbrain/node-ssh 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。