Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
474 views
in Technique[技术] by (71.8m points)

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

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.

[manual shell session]

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...