ssh via java prompting for password

Hi,

I have set up my remote server for password-less login via ssh. If I run the command on my server - ssh user@remoteserver "ls -l"
I get an output, but when I try to do this via java

String[] sCmd = new String[]{"/usr/bin/ssh", " user@remoteserver", "\"ls -l\""};
Process p = Runtime.getRuntime().exec(sCmd);

int c;
InputStream in = p.getInputStream();
while ((c = in.read()) != -1) {
    System.out.print((char) c);
}

it will prompt me for the user password. :confused:

Any insight is highly appreciated.

OS- AIX
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build pap64dev-20071008 (SR6))
IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 AIX ppc64-64 j9vmap6423-20071007 (JIT enabled)
J9VM - 20071004_14218_BHdSMr
JIT - 20070820_1846ifx1_r8
GC - 200708_10)
JCL - 20071008

$ ssh -V
OpenSSH_5.2p1, OpenSSL 0.9.8k 25 Mar 2009

Remember, it has to be able to access the user's own identity keys, generally /home/user/.ssh/id_dsa, for passwordless ssh. The Java VM has to be able to access the files and know where they are. Try pointing it to the right files with the -i switch. Also try "-v" to print debugging information. "-vv" and "-vvv" are progressively more wordy.

Today, I tried with the -i switch as well, it is still prompting for password.

Most confusing part is that I am running the command and java program as the same local user. Command does not prompt for pwd but the java process does...i'm still looking for answers

Java runs inside a virtual machine, independent of stuff you run. This virtual machine may not have permissions to access these files.

Have you tried running ssh with -v, -vv, -vvv like I suggested? It may print error messages that tell you precisely what's going wrong.