JSch: sudo sometimes not working -
I have three machines and I need to do them I need JSch to do the following things: This is a code block that I use to run JSch: My problem is that I can successfully use this program to get the status of the eDire service on two of the three machines, but not the last. I can ssh in the remote machine with the given username and then run this command directly: ssh is already configured in my So, my questions are: Why JSCH can run this program on two of the three machines, while no one else can? Sudoers' configuration is exactly the same on these machines. And another question is: sudo on the real machine why the password can run again without typing if i configured the current user in sudoers, while JSch sudo program Need a password in? Any guidelines really appreciate if I have some possible errors that may occur in my current circumstances, let them know all. Thank you. What output do you get with JSK Sudo attempts on unsuccessful machines? To receive the required error message: SSI server probably has different settings on your server. You need pty: Usually you need to type your password once per session for pseudo. Maybe you had already poked on the actual machine and did not log out. The above code connects again every time, so it needs to send the password every time. ssh , once again, and Then sudo a command
ssh < User & gt; @ & Lt; Machine & gt; Sudo & lt; Some orders & gt;
string homefolder = System.getProperty ("user.home"); JSch jsch = new JSch (); Jsch.addIdentity (homefolder + "/.ssh/id_rsa.pub"); Jsch.setKnowHosts (Homefolder + "/.ssh/known_hosts"); Last session session = jsch.getSession (user, machine); Session.connect (); StringBilder Response = New StringBuilder (); {Try Last Channel Channel = Session. Openchannel ("exec"); ((Channel XAC) channel) .setCommand ("Pado / ATC / Intact DC / ADR Status") channel.connect (); Try in {InputStream = channel.getInputStream (); Output Stream Out = channel.getOutputStream (); Out.written ((password + system.zipproperty ("line separator")). ()); BufferedReader Reader = new BufferedReader (new InputStreamReader (in)); String line = null; While (empty! = (Line = reader. Readline ()) {System.out.println (line); }} Finally {channel.disconnect (); }} Finally {session.disconnect (); }
sudo /etc/init.d/eedir The user name used in the status
/ etc / sudoers .
(ChannelExec) commandChannel.getErrStream ();
(ChannelExec) commandChannel.setPty (true); (ChannelExec) commandChannel.setPtyType ("VT100");
Comments
Post a Comment