Created
December 11, 2019 08:53
-
-
Save choowilson/b6d45a3e9d3add630f341d226e7af85f to your computer and use it in GitHub Desktop.
use SSHJ to ssh to target and run a command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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