Commands executed using JSch behaves differently than in SSH terminal (bypasses confirm prompt message of “yes/”no")

左心房为你撑大大i 提交于 2019-12-17 16:53:43

问题


Note: I log into a device, not a computer, so I login to configuration mode (instead of non configuration mode).

I am using JSch library in Java, to login with an SSH protocol. I login like this:

channel = con.openChannel("shell");
channel.connect();

In some cases, when I send through the shell a command that needs su (configuration mode) permissions (change configuration), this code bypasses the prompt confirmation message of - this may prevent other users from changing configuration. While if I enter the command manually with SSH client/terminal, I have to enter yes for confirmation.

Does anyone have any idea why?
Thanks.

[

]

When I log in through JSch I can do the configuration commands even, when the I don't insert "yes" to the array of commands to be executed.


回答1:


By default the JSch does not request PTY (pseudo-terminal).

That can cause some commands to behave differently than in an interactive SSH terminal.

You can override this using the ChannelSession.setPty.


If the above does not help, see also similar questions:

  • Certain Unix commands fail with "... not found", when executed through Java using JSch
  • Certain Unix commands fail with "... not found", when executed through Java using JSch even with setPty enabled


来源:https://stackoverflow.com/questions/41985191/commands-executed-using-jsch-behaves-differently-than-in-ssh-terminal-bypasses

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