Use pty with ssh2 in node to execute command with sudo

荒凉一梦 提交于 2019-12-06 07:22:16

You have to parse the stream output for the sudo prompt. At that point, you have to stream.write(password + '\n');. The alternative to doing all of that is to modify /etc/sudoers so that the logged in user can execute sudo for a specific program/script/whatever without a password.

flaalf

I think you should place the stream.write(password + '\n'); right after the stream.on('exit',.... line.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!