SSHClient ssh = new SSHClient(); //ssh.useCompression(); ssh.loadKnownHosts(); ssh.connect("localhost"); try { ssh.authPublickey(System.getProperty("user.name")); new SCPDownloadClient(ssh).copy("ten", "/tmp"); } finally { ssh.disconnect(); }
public SSHClient setupClient(Config config) { if (client == null) { client = new SSHClient(config); client.addHostKeyVerifier(fingerprint); } return client; }
final SSHClient ssh = new SSHClient(); ssh.addHostKeyVerifier( new HostKeyVerifier() { public boolean verify(String arg0, int arg1, PublicKey arg2) { return true; // don't bother verifying } } ); ssh.connect("LocalHost");
private void build() throws IOException { if (init) { return; } ssh = new SSHClient(); ssh.addHostKeyVerifier(new HostKeyVerifier() { @Override public boolean verify(String arg0, int arg1, PublicKey arg2) { return true; } }); ssh.connect(hostname, port); if (privateKey != null) { privateKeyFile = File.createTempFile("zstack", "tmp"); FileUtils.writeStringToFile(privateKeyFile, privateKey); ssh.authPublickey(username, privateKeyFile.getAbsolutePath()); } else { ssh.authPassword(username, password); } init = true; }
SSHClient ssh = new SSHClient(); ssh.loadKnownHosts(); ssh.connect("nameOfServer"); ssh.authPublickey("userId"); Session session = ssh.startSession(); Command cmd = session.exec("yourCommand"); System.out.println(cmd.getOutputAsString()); session.close(); ssh.disconnect();
public SSHClient getSSHClient() { if (sshClient == null) { sshClient = new SSHClient(); } return sshClient; }
public SSHProvider() { ssh = new SSHClient(); }
... final SSHClient ssh = new SSHClient(); ssh.addHostKeyVerifier(new NullHostKeyVerifier()); ...
SSHClient client = new SSHClient(); String username = "johndoe"; File privateKey = new File("~/.ssh/id_rsa"); KeyProvider keys = client.loadKeys(privateKey.getPath()); client.authPublicKey(username, keys);
/** * @return SSHClient with Android Configuration */ public SSHClient newAndroidSSHClient() { return new SSHClient(new AndroidConfig()); }
try { ssh.connect(envConf.getIp(), port); } catch (TransportException e) { if (e.getDisconnectReason() == DisconnectReason.HOST_KEY_NOT_VERIFIABLE) { String msg = e.getMessage(); String[] split = msg.split("`"); String vc = split[3]; ssh = new SSHClient(); ssh.addHostKeyVerifier(vc); ssh.connect(envConf.getIp(), port); } else { throw e; } } ssh.authPassword(envConf.getName(), envConf.getPw()); ssh.newSCPFileTransfer().download(envConf.getHomePath() + FilePath, toPath);
SSHClient ssh = new SSHClient(); ssh.loadKnownHosts(); ssh.connect("your-server"); ssh.authPublickey("userId"); //START SESSION Session session = ssh.startSession(); //SEND THE COMMAND Command cmd = session.exec("shutdown"); //GET THE OUTPUT OF COMMAND cmd.getOutputAsString(); //CLOSE SESSION session.close(); ssh.disconnect();
private void configureConnection(String serverFingerPrint, Boolean checkIdentity) throws IOException { createKnownHosts(); ssh = new SSHClient(); ssh.loadKnownHosts(); if (!checkIdentity) { ssh.addHostKeyVerifier(new PromiscuousVerifier()); } else if (serverFingerPrint != null) { ssh.addHostKeyVerifier(serverFingerPrint); } else { File khFile = new File(OpenSSHKnownHosts.detectSSHDir(), "known_hosts"); ssh.addHostKeyVerifier(new OpenSSHKnownHosts(khFile)); } }
final SSHClient ssh = new SSHClient(); ssh.loadKnownHosts(); // or, to skip host verification: ssh.addHostKeyVerifier(new PromiscuousVerifier()) ssh.connect("localhost"); try { ssh.authPassword("user", "password"); // or ssh.authPublickey(System.getProperty("user.name")) final SFTPClient sftp = ssh.newSFTPClient(); try { sftp.get("test_file", "/tmp/test.tmp"); } finally { sftp.close(); } } finally { ssh.disconnect(); }
public void sshExec(String cmd) throws IOException { @SuppressWarnings("resource") final SSHClient ssh = new SSHClient(); ssh.addHostKeyVerifier(new PromiscuousVerifier()); try { ssh.connect("localhost", vm.getSshForwardPort()); ssh.authPassword("root", ""); try (Session session = ssh.startSession()) { final Session.Command sessionCmd = session.exec(cmd); sessionCmd.join(5, TimeUnit.SECONDS); int exitCode = sessionCmd.getExitStatus(); if (exitCode != 0) { throw new RuntimeException("command " + cmd + " returned exit status code " + exitCode); } } } finally { if (ssh.isConnected()) { ssh.disconnect(); } } }
/** * Create a new {@code SSHClient} connected to the remote machine using the * AdminAccess credentials as provided */ public static SSHClient newClient( Machine machine, AdminAccess adminAccess, int timeoutInMillis ) throws IOException { checkArgument(timeoutInMillis >= 0, "timeoutInMillis should be positive or 0"); final SSHClient client = new SSHClient(); client.addHostKeyVerifier(AcceptAnyHostKeyVerifier.INSTANCE); if (timeoutInMillis != 0) { client.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT); client.setTimeout(timeoutInMillis); } client.connect(machine.getPublicDnsName(), machine.getSshPort()); OpenSSHKeyFile key = new OpenSSHKeyFile(); key.init(adminAccess.getPrivateKey(), adminAccess.getPublicKey()); client.authPublickey(adminAccess.getUsername(), key); return client; }
public Session getSession(String hostAddress) throws IOException { try { if (sshClient == null) { sshClient = new SSHClient(); } if (getSSHClient().isConnected()) return getSSHClient().startSession(); KeyProvider pkey = getSSHClient().loadKeys(getPrivateKeyLoc(), getKeyPass()); getSSHClient().loadKnownHosts(); getSSHClient().connect(hostAddress); getSSHClient().authPublickey(getUsername(), pkey); session = getSSHClient().startSession(); return session; } catch (NullPointerException ne) { throw new SecurityException("Cannot load security context for SSH", ne); } }
@Override public SSHClient create() throws Exception { ssh = new net.schmizz.sshj.SSHClient(); ssh.addHostKeyVerifier(new PromiscuousVerifier()); if (connectTimeout != 0) { ssh.setConnectTimeout(connectTimeout); } if (sessionTimeout != 0) { ssh.setTimeout(sessionTimeout); } ssh.connect(hostAndPort.getHostText(), hostAndPort.getPortOrDefault(22)); if (loginCredentials.getPassword() != null) { ssh.authPassword(loginCredentials.getUser(), loginCredentials.getPassword()); } else { OpenSSHKeyFile key = new OpenSSHKeyFile(); key.init(loginCredentials.getPrivateKey(), null); ssh.authPublickey(loginCredentials.getUser(), key); } return ssh; }
@Override public SSHClient create() throws Exception { ssh = new net.schmizz.sshj.SSHClient(); ssh.addHostKeyVerifier(new PromiscuousVerifier()); if (connectTimeout != 0) { ssh.setConnectTimeout(connectTimeout); } if (sessionTimeout != 0) { ssh.setTimeout(sessionTimeout); } ssh.connect(hostAndPort.getHostText(), hostAndPort.getPortOrDefault(22)); if (loginCredentials.getPassword() != null) { ssh.authPassword(loginCredentials.getUser(), loginCredentials.getPassword()); } else { OpenSSHKeyFile key = new OpenSSHKeyFile(); key.init(loginCredentials.getPrivateKey(), null); ssh.authPublickey(loginCredentials.getUser(), key); } return ssh; }
@Override public SSHClient create() throws Exception { ssh = new net.schmizz.sshj.SSHClient(); ssh.addHostKeyVerifier(new PromiscuousVerifier()); if (connectTimeout != 0) { ssh.setConnectTimeout(connectTimeout); } if (sessionTimeout != 0) { ssh.setTimeout(sessionTimeout); } ssh.connect(hostAndPort.getHostText(), hostAndPort.getPortOrDefault(22)); if (loginCredentials.getPassword() != null) { ssh.authPassword(loginCredentials.getUser(), loginCredentials.getPassword()); } else { OpenSSHKeyFile key = new OpenSSHKeyFile(); key.init(loginCredentials.getPrivateKey(), null); ssh.authPublickey(loginCredentials.getUser(), key); } return ssh; }