需要借助Ganymed SSH的jar包: ganymed-ssh2-262.jar
下载地址: http://www.ganymed.ethz.ch/ssh2/
API详情: http://www.ganymed.ethz.ch/ssh2/javadoc/ch/ethz/ssh2/package-summary.html
https://blog.csdn.net/zhufengyan521521/article/details/82871437
https://www.cnblogs.com/shuaiqing/p/5664253.html
实用:https://my.oschina.net/liuyuanyuangogo/blog/186159
Connection conn = new Connection(hostname,port); Session ssh = null; 1、连接主机:conn.connect() 2、用户名+密码:conn.authenticateWithPassword(username, password) 3、执行命令 3.1、创建与服务器的会话节点:ssh = conn.openSession(); 3.2、执行Linux命令:ssh.execCommand("sh /root/hello.sh");