java代码连接Linux虚拟机
<dependency>
<groupId>ch.ethz.ganymed</groupId>
<artifactId>ganymed-ssh2</artifactId>
<version>262</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
public static Connection login(String host,String username,String password){
username="username";
password="password";
host="host";
boolean flag=false;
Connection connection=null;
connection=new Connection(host);
try {
connection.connect();
flag=connection.authenticateWithPassword(username,password);
if (flag){
System.out.println("登录成功!");
}
} catch (IOException e) {
System.out.println("登录失败!");
e.printStackTrace();
}
return connection;
}