[英]Can I hand off from a node cli app to bash?
I'm working on a fairly simple node cli application for my agency that allows you to add clients and any of their sites to a db (lowdb) and then basically run the script with the client name to hand you off to an ssh session on their server.我正在为我的代理机构开发一个相当简单的节点 cli 应用程序,它允许您将客户端及其任何站点添加到数据库(lowdb),然后基本上使用客户端名称运行脚本,将您交给 ssh session他们的服务器。 I've tried the
exec
module, but it's just showing the password or key password prompt from ssh and not allowing me to actually continue with the session.我已经尝试过
exec
模块,但它只是显示来自 ssh 的密码或密钥密码提示,并且不允许我实际继续使用 session。
I'm wondering if there is a clean way to basically execute that initial ssh
command but then just be running that on bash and not through the node app?我想知道是否有一种干净的方法可以基本上执行初始
ssh
命令,然后只是在 bash 上运行它而不是通过节点应用程序?
For example: If I use the following code...例如:如果我使用以下代码...
exec('ssh [options we always need] client@clientserver.com');
I get the following...我得到以下...
$ client's password: []
But it's just printing the stdout, not allowing me to continue with the session.但它只是打印标准输出,不允许我继续使用 session。 I just want the node cli to effectively end after starting the bash command running, allowing the user to login and continue as usual.
我只希望节点 cli 在启动 bash 命令运行后有效结束,允许用户像往常一样登录并继续。
Why not just use a dedicated library instead of the command-line interface?为什么不直接使用专用库而不是命令行界面? Simply, implement the API and get the console input for the 'password', and then just pipe all command-line input to the SSH stream.
Simply, implement the API and get the console input for the 'password', and then just pipe all command-line input to the SSH stream.
With node-ssh-forward , you simply establish a connection with the server using the input from the CLI and use the sshConnection.executeCommand('')
command with the input from the user.使用node-ssh-forward ,您只需使用来自 CLI 的输入建立与服务器的连接,并使用来自用户的输入的
sshConnection.executeCommand('')
命令。 This library also supports callbacks so you can just console.log the results from the callback.该库还支持回调,因此您只需 console.log 回调的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.