0

I've tried

Runtime.getRuntime().exec("ssh guest@guest password");
Runtime.getRuntime().exec("do something at guest@guest");

But this prompts me for password. I would like to automate ssh login and do something like create a file in the remote client.

What's the best way to do this?

Thanks

drum
  • 5,416
  • 7
  • 57
  • 91

2 Answers2

1

The best way to automate the login is by setting up ssh keys. See the HOWTO.

As to the actual ssh interaction, instead of executing the external command, it probably makes sense to use a suitable library. See SSH library for Java for some pointers.

Community
  • 1
  • 1
NPE
  • 486,780
  • 108
  • 951
  • 1,012
1

You might consider this library

http://www.jcraft.com/jsch/index.html

Or sshj

https://github.com/shikhar/sshj/

Here you will find a similar question: Send ssh command from Java code

Community
  • 1
  • 1
tgoossens
  • 9,676
  • 2
  • 18
  • 23