can anybody show moe how to send from java ssh command ( example ssh [email protected] "ls" ) ? What class do I need ?
-
possible dublicates stackoverflow.com/questions/570450/… and stackoverflow.com/questions/995944/ssh-library-for-javauser467871– user4678712011-01-18 11:33:49 +00:00Commented Jan 18, 2011 at 11:33
-
Remote access for root? Generally not recommended.Qwerky– Qwerky2011-01-18 12:30:43 +00:00Commented Jan 18, 2011 at 12:30
-
you can use JSch library, but dont do directory listing with command "ls", better use sftp from the same library JSch, much easier to browse remote filesystem.Ruslan– Ruslan2011-01-18 12:45:35 +00:00Commented Jan 18, 2011 at 12:45
-
Does this answer your question? SSH library for JavaEdChum– EdChum2020-07-20 08:02:28 +00:00Commented Jul 20, 2020 at 8:02
Add a comment
|
3 Answers
Using sshj:
SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
ssh.connect("nameOfServer");
ssh.authPublickey("userId");
Session session = ssh.startSession();
Command cmd = session.exec("yourCommand");
System.out.println(cmd.getOutputAsString());
session.close();
ssh.disconnect();
1 Comment
Leonid Dashko
Thanks for the option. Just bear in mind that this library has 5 library dependencies.