Exec commands in interactive mode

Help
Anonymous
2009-12-03
2013-05-28

  • Anonymous
    2009-12-03

    Hi,

    I am trying to change the UNIX password using passwd command. passwd command has got some prompts depending on the Operating system. Using Jsch i tried to establish connection and execute the command.

            JSch jsch = new JSch();
            Session session = jsch.getSession(username, hostname, 22);
            UserInfo ui = new MyUserInfo();
            session.setUserInfo(ui);
            session.connect(30000);
            Channel channel = session.openChannel("exec");
            ((ChannelExec) channel).setCommand("passwd " + username);
            ((ChannelExec) channel).setPty(true);
            channel.setInputStream(null);
            ((ChannelExec) channel).setErrStream(System.err);
            InputStream in = channel.getInputStream();
            channel.setInputStream(in);
            channel.setOutputStream(System.out);
            channel.connect();
    After giving the value to the first prompt, Enter existing login password: , it is prompting the next prompt. It appears ssh connection is not handling the 2-way communication. Please help me out to resolve the issue.

    Thanks