本文整理汇总了Java中net.schmizz.sshj.SSHClient.loadKnownHosts方法的典型用法代码示例。如果您正苦于以下问题:Java SSHClient.loadKnownHosts方法的具体用法?Java SSHClient.loadKnownHosts怎么用?Java SSHClient.loadKnownHosts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.schmizz.sshj.SSHClient
的用法示例。
在下文中一共展示了SSHClient.loadKnownHosts方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeCommand
import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Override
public String executeCommand(ShellCommand aCommand) throws IOException {
SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
ssh.connect("localhost", 2222);
try {
ssh.authPublickey("root");
try (Session session = ssh.startSession()) {
Session.Command command = session.exec(aCommand.getCommand());
String text = IOUtils.readFully(command.getInputStream()).toString();
command.join(5, TimeUnit.SECONDS);
return text;
}
} finally {
ssh.disconnect();
}
}
示例2: connect_to_virtual_box
import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Test
public void connect_to_virtual_box() throws IOException {
SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
ssh.connect("localhost", 2222);
try {
ssh.authPublickey("root");
try (Session session = ssh.startSession()) {
Session.Command command = session.exec("ls -l");
System.out.println(IOUtils.readFully(command.getInputStream()).toString());
command.join(5, TimeUnit.SECONDS);
}
} finally {
ssh.disconnect();
}
}
示例3: connect
import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Override
public void connect(String host) throws IOException {
sshClient = new SSHClient();
if (knownHosts == null) {
sshClient.loadKnownHosts();
} else {
sshClient.loadKnownHosts(knownHosts.toFile());
}
sshClient.connect(host);
if (privateKey != null) {
sshClient.authPublickey(user, privateKey.toString());
} else if (password != null) {
sshClient.authPassword(user, password);
} else {
throw new RuntimeException("Either privateKey nor password is set. Please call one of the auth method.");
}
}
示例4: configureSsh
import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
private SSHClient configureSsh() throws IOException {
SSHClient sshClient = new SSHClient();
sshClient.loadKnownHosts();
sshClient.connect(eyeballsConfiguration.getSftpDestinationHost(), eyeballsConfiguration.getSftpRemotePort());
sshClient.authPublickey(eyeballsConfiguration.getSftpUsername());
sshClient.useCompression();
return sshClient;
}
示例5: connectWithSSH
import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
private SSHClient connectWithSSH() throws IOException {
SSHClient ssh = mSSHClientFactory.newSSHClient();
ssh.loadKnownHosts();
ssh.connect(mRemoteInetAddress);
ssh.authPublickey(mUsername, mPrivateKeyPath.toString());
return ssh;
}