JSch: sudo sometimes not working -


I have three machines and I need to do them ssh , once again, and Then sudo a command

I need JSch to do the following things:

  ssh < User & gt; @ & Lt; Machine & gt; Sudo & lt; Some orders & gt;   

This is a code block that I use to run JSch:

  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 (); }   

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:

  sudo /etc/init.d/eedir The user name used in the status   

ssh is already configured in my / etc / sudoers .

So, my questions are:

  1. 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.

  2. 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.

    1. What output do you get with JSK Sudo attempts on unsuccessful machines? To receive the required error message:

        (ChannelExec) commandChannel.getErrStream ();   

      SSI server probably has different settings on your server. You need pty:

        (ChannelExec) commandChannel.setPty (true); (ChannelExec) commandChannel.setPtyType ("VT100");  
    2. 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.

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -