Skip to content

Instantly share code, notes, and snippets.

@choowilson
Created December 11, 2019 08:53
Show Gist options
  • Save choowilson/b6d45a3e9d3add630f341d226e7af85f to your computer and use it in GitHub Desktop.
Save choowilson/b6d45a3e9d3add630f341d226e7af85f to your computer and use it in GitHub Desktop.
use SSHJ to ssh to target and run a command
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.connection.channel.direct.Session;
import net.schmizz.sshj.transport.verification.PromiscuousVerifier;
import java.io.IOException;
public class sendCommand {
public static void main(String[] args) throws IOException {
final SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier(new PromiscuousVerifier());
ssh.connect("192.168.1.100",22);
try {
ssh.authPassword("pi", "142536");
final Session session = ssh.startSession();
try {
// final Session.Command cmd = session.exec("echo 142536 | sudo -S reboot");
final Session.Command cmd = session.exec("python testGPIO.py");
} finally {
session.close();
}
} finally {
ssh.disconnect();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment