how to do a sudo after logging in?

ronald.van.de.kuil@nl.abnamro.com ronald.van.de.kuil@nl.abnamro.com
Tue, 20 Jul 2004 18:20:20 +0200




Hello,

I want to sudo after logging in with my user id but I don't know how to
insert the password.

I have written the following method:

public void connect(String aAddress, String aUser, String aSudoUser, String
aPassword, int aPort) throws IOException {

      Socket serverSocket     = new Socket(aAddress, aPort);
      SSH2Transport transport = new SSH2Transport(serverSocket, prefs,
createSecureRandom());

      System.out.println("SSH2-login on " + aAddress + " with user " +
aUser);

      try {
            lClient = new SSH2SimpleClient(transport, aUser, aPassword);
            lConsole = new SSH2ConsoleRemote(lClient.getConnection(), null,
System.err);

            //until here it works fine

            if (null != aSudoUser){
                  String lCommand = "sudo su - " + aSudoUser;
                  System.out.println("SSH2IO>" + lCommand + "<");
                  lConsole.command(lCommand );

                  /**
                  * Here the program asks for my password depending on the
last time I logged in
                  * The thread continues without waiting for input and
prints my working directory
                  * instead of the working directory of the user I want to
su to
                  "/

                  lConsole.command("pwd");
                  String response = receive();
                  System.out.println(response);
            }
            } catch (SSH2Exception e) {
                  System.out.println("Trouble connecting to aAddress " +
e);
            }
      }
}

I seem to be getting  a prompt from standard err asking me for a password
but I don't manage to insert the password.
It doesn't help to inserting the password by adding
lConsole.command(aPassword);

When I do a sudo from a terminal, the code doesn't ask for my password
anymore but the result is still that I get my personal
working directory printed.

Can anyone point me to some sample code where a sudo is done?

Regards,

Ronald van de Kuil
SDTCCC 838443

---------------------------------------------------------------------------
This message (including any attachments) is confidential and may be
privileged. If you have received it by mistake please notify the sender by
return e-mail and delete this message from your system. Any unauthorised
use or dissemination of this message in whole or in part is strictly
prohibited. Please note that e-mails are susceptible to change.
ABN AMRO Bank N.V. (including its group companies) shall not be liable for
the improper or incomplete transmission of the information contained in
this communication nor for any delay in its receipt or damage to your
system. ABN AMRO Bank N.V. (or its group companies) does not guarantee that
the integrity of this communication has been maintained nor that this
communication is free of viruses, interceptions or interference.
---------------------------------------------------------------------------