Jsch and sudo command

青春壹個敷衍的年華 提交于 2019-12-01 14:16:00
Martin Prikryl

You cannot pass a password to sudo with input redirection, at least not with the default configuration.

Hence, this cannot work:

echo 'targetPass' | sudo -S -p /bin/rootsh -i -u technicalUser` 

Did you even try it in the interactive terminal? I assume it would not work there either.


You have to write the password to the channel input stream (called "output stream" in JSch).

See the official JSch Sudo example.

You may need to enable TTY/PTY. See Use JSch sudo example and Channel.setPty for running sudo command on remote host.

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