JSch: sudo <some command> sometimes not working
===

Now I have three machines where I need to first ssh to them one by one, and then sudo some command.

The goal I want to achieve is that the JSch could do the following things as I described as the previous section. i.e.:

    ssh <user>@<machine>
    sudo <some command>

And this is the code block how I use the JSch to do these things:

    String homeFolder = System.getProperty("user.home");
    JSch jsch = new JSch();
    jsch.addIdentity(homeFolder + "/.ssh/id_rsa.pub");
    jsch.setKnowHosts(homeFolder + "/.ssh/known_hosts");
    
    final Session session = jsch.getSession(user, machine);
    session.connect();
    
    StringBuilder response = new StringBuilder();
    try {
        final Channel channel = session.openChannel("exec");
        ((ChannelExec) channel).setCommand("sudo /etc/init.d/eedir status")
        channel.connect();

        try {
            InputStream in = channel.getInputStream();
            OutputStream out = channel.getOutputStream();
            
            out.write((password + System.getProperty("line.separator")).getBytes());
            
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            String line = null;
            while (null != (line = reader.readLine())) {
                System.out.println(line);
            }
        } finally {
            channel.disconnect();
        }
    } finally {
        session.disconnect();
    }

My problem is that I can use this program successfully to get the status of the eedir service on two of the three machines I have, but the last one cannot.

**I promise that I can first ssh to the remote machine with the given user name and then "sudo /etc/init.d/eedir status" on my real machine.** The username used in 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 the rest one cannot? The sudoers' configuration is exactlly the same on these machines.
2. And another question is: why sudo <some command> on the real machine can run without typing the password again if I configured the current user in sudoers, while JSch sudo require the password in the program?

Any directions are really appreciated. If there are some potential errors that I might have under my current circumstances, welcome everybody to point them out.

Thanks.