Search code examples
javashellsshpasswordsnon-interactive

non-interactive password SSH in JAVA


I have a program that requires cascaded SSH, i.e. it ssh A server and then using same connection ssh B server. Server A is acting as a bridge. I have an instance of shell which is used to ssh first server.

When I am doing ssh user@ipAddress, it asks for password. I tried ssh user@ipAddress\npassword. It doesn't seem to be working.

I cannot use any external tools like ssh-agent or expect. I have no control over the server A.

Is there a way I can provide password as an argument or enter password?

Thanks!!


Solution

  • You should generate a RSA key on the client

    ssh-keygen
    

    and put the public key in the authorized key in the authorized_key folder on the server to be able to connect to the server without a password.

    An step by step guide is given here.

    Edit: If you have no access to the server, use a ssh-library for Java as decrived in this question.