本文整理汇总了Java中net.schmizz.sshj.SSHClient.authPassword方法的典型用法代码示例。如果您正苦于以下问题:Java SSHClient.authPassword方法的具体用法?Java SSHClient.authPassword怎么用?Java SSHClient.authPassword使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.schmizz.sshj.SSHClient
的用法示例。
在下文中一共展示了SSHClient.authPassword方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectfromPItoServer
import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
public static void connectfromPItoServer(int fotosAnzahl, int belichtungsDauer)
throws IOException {
final String ipServer = Inet4Address.getLocalHost().getHostAddress();
// System.out.println(Inet4Address.getAllByName("raspberrypi"));
// System.out.println(fotosAnzahl);
final SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier(new NullHostKeyVerifier());
// for(int i = 0; i < InetAddress.)
// ssh.connect("192.168.2.100", 22);
ssh.connect(Settings.raspberryIP, 22);
try {
ssh.authPassword("pi", "raspberry");
final Session session = ssh.startSession();
try {
System.out.println("BEGINNE MIt tray");
final Command cmd = session.exec("java -jar Desktop/Driver/Java/client.jar " + fotosAnzahl + " " + ipServer + " " + belichtungsDauer);
System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
cmd.join(5, TimeUnit.SECONDS);
System.out.println("\n** exit status: " + cmd.getExitStatus());
} finally {
session.close();
}
} finally {
ssh.disconnect();
ssh.close();
}
}
示例2: build
import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
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;
}
示例3: SshConnection
import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
/**
* Connects to a ssh server
*
* <p>
* Do not call this constructor directly, use {@link SshConnector} instead for IoC
*
* @param config the ssh configuration
* @param client an instance of {@link SSHClient} to use
* @throws IOException failed to connect to the server
*/
public SshConnection(SshConfig config, SSHClient client) throws IOException {
// TODO see if the SSHClient can be injected differently
this.client = client;
this.config = config;
if (!config.getVerifyHostKey()) {
client.addHostKeyVerifier(new PromiscuousVerifier());
}
client.connect(config.getHost(), config.getPort());
if (config.getPassword() != null) {
client.authPassword(config.getUser(), config.getPassword());
} else if (config.getKeyFile() != null) {
client.authPublickey(config.getUser(), config.getKeyFile().toString());
} else {
client.authPassword(config.getUser(), "");
}
}
示例4: 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.");
}
}
示例5: upload
import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
/**
* Uploads a local file (or directory) to the remote server via SCP.
*
* @param address the hostname or IP address of the remote server.
* @param username the username of the remote server.
* @param password the password of the remote server.
* @param localPath a local file or directory which will be uploaded.
* @param remotePath the destination path on the remote server.
* @throws Exception
*/
public void upload(String address, String username, String password, String localPath, String remotePath) throws Exception {
SSHClient client = newSSHClient();
client.connect(address);
logger.debug("Connected to hostname %s", address);
try {
client.authPassword(username, password.toCharArray());
logger.debug("Successful authentication of user %s", username);
client.newSCPFileTransfer().upload(new FileSystemFile(new File(localPath)), remotePath);
logger.debug("Successful upload from %s to %s", localPath, remotePath);
} finally {
client.disconnect();
logger.debug("Disconnected to hostname %s", address);
}
}
示例6: download
import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
/**
* Downloads a remote file (or directory) to the local directory via SCP.
*
* @param address the hostname or IP address of the remote server.
* @param username the username of the remote server.
* @param password the password of the remote server.
* @param remotePath a remote file or directory which will be downloaded.
* @param localPath the destination directory on the local file system.
* @throws Exception
*/
public void download(String address, String username, String password, String remotePath, String localPath) throws Exception {
SSHClient client = newSSHClient();
client.connect(address);
logger.debug("Connected to hostname %s", address);
try {
client.authPassword(username, password.toCharArray());
logger.debug("Successful authentication of user %s", username);
client.newSCPFileTransfer().download(remotePath, new FileSystemFile(new File(localPath)));
logger.debug("Successful download from %s to %s", remotePath, localPath);
} finally {
client.disconnect();
logger.debug("Disconnected to hostname %s", address);
}
}
示例7: doInBackground
import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Override
protected Boolean doInBackground(String... cmd) {
String ssh_command = cmd[0];
SSHClient ssh = new SSHClient();
HostKeyVerifier always_verify = new HostKeyVerifier() {
public boolean verify(String arg0, int arg1, PublicKey arg2) {
return true;
}
};
ssh.addHostKeyVerifier(always_verify);
Boolean success = false;
try {
ssh.connect(this.ssh_server);
ssh.authPassword(this.ssh_user, this.ssh_password);
Session session = ssh.startSession();
Command command = session.exec(ssh_command);
command.join();
Integer exit_status = command.getExitStatus();
if (exit_status == this.expected_exit_status) {
success = true;
}
session.close();
ssh.close();
} catch (IOException e) { }
return success;
}
示例8: prepareSshConnection
import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
private void prepareSshConnection(SSHClient ssh, String ip, int port, HostKeyVerifier hostKeyVerifier, String user,
String privateKeyString, Stack stack) throws CloudbreakException, IOException {
ssh.addHostKeyVerifier(hostKeyVerifier);
ssh.connect(ip, port);
if (stack.getStackAuthentication().passwordAuthenticationRequired()) {
ssh.authPassword(user, stack.getStackAuthentication().getLoginPassword());
} else {
try {
KeyPair keyPair = KeyStoreUtil.createKeyPair(privateKeyString);
KeyPairWrapper keyPairWrapper = new KeyPairWrapper(keyPair);
ssh.authPublickey(user, keyPairWrapper);
} catch (Exception e) {
throw new CloudbreakException("Couldn't prepare SSH connection", e);
}
}
}
示例9: getTempLocalInstance
import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
public File getTempLocalInstance( String remoteFilePath )
{
File tempFile = null;
SSHClient client = new SSHClient();
// required if host is not in knownLocalHosts
client.addHostKeyVerifier(new PromiscuousVerifier());
try {
client.connect(hostName);
client.authPassword(userName, userPass);
tempFile = File.createTempFile("tmp", null, null);
tempFile.deleteOnExit();
SFTPClient sftp = client.newSFTPClient();
sftp.get(remoteFilePath, new FileSystemFile(tempFile));
sftp.close();
client.disconnect();
} catch( Exception e ) {
//TODO: this needs to be more robust than just catching all exceptions
e.printStackTrace();
logger.error( e.toString() );
return null;
}
return tempFile;
}
示例10: getConnectedClient
import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
private SSHClient getConnectedClient() throws Exception {
if (password == null && key == null)
throw new Exception("You need to provide one among the key and the password to be used.");
DefaultConfig defaultConfig = new DefaultConfig();
defaultConfig.setKeepAliveProvider(KeepAliveProvider.KEEP_ALIVE);
final SSHClient ssh = new SSHClient(defaultConfig);
ssh.addHostKeyVerifier(new PromiscuousVerifier());
ssh.connect(ip, SSH_PORT);
if (key != null) {
if (!key.endsWith(".pem"))
key = key.concat(".pem");
Path p = Configuration.getPathToFile(key);
if (p != null)
ssh.authPublickey(user, p.toString());
} else {
ssh.authPassword(user, password);
}
ssh.getConnection().getKeepAlive().setKeepAliveInterval(5);
return ssh;
}
示例11: initialize
import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@PostConstruct
public void initialize() throws Exception {
ssh = new SSHClient();
ssh.addHostKeyVerifier(new HostKeyVerifier() {
@Override
public boolean verify(final String s, final int i, final PublicKey publicKey) {
return true;
}
});
ssh.connect(cecSshHost);
ssh.authPassword(cecSshUser, cecSshPass);
session = ssh.startSession();
command = session.exec(String.format("cec-client --osd-name \"%s\"", cecOsdName));
outputStream = command.getOutputStream();
inputStream = command.getInputStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
printWriter = new PrintWriter(outputStreamWriter);
streamGobbler = new StreamGobbler(inputStream, new StreamGobbler.OnLineListener() {
@Override
public void onLine(final String line) {
logger.info("CEC: " + line);
for (LineHandler lineHandler : lineHandlerList) {
lineHandler.onLine(line);
}
}
});
streamGobbler.start();
}
示例12: main
import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier(
new HostKeyVerifier() {
@Override
public boolean verify(String s, int i, PublicKey publicKey) {
return true;
}
});
ssh.connect("sdf.org");
ssh.authPassword("new", "");
Session session = ssh.startSession();
session.allocateDefaultPTY();
Shell shell = session.startShell();
Expect expect = new ExpectBuilder()
.withOutput(shell.getOutputStream())
.withInputs(shell.getInputStream(), shell.getErrorStream())
.withEchoInput(System.out)
.withEchoOutput(System.err)
.withInputFilters(removeColors(), removeNonPrintable())
.withExceptionOnFailure()
.build();
try {
expect.expect(contains("[RETURN]"));
expect.sendLine();
String ipAddress = expect.expect(regexp("Trying (.*)\\.\\.\\.")).group(1);
System.out.println("Captured IP: " + ipAddress);
expect.expect(contains("login:"));
expect.sendLine("new");
expect.expect(contains("(Y/N)"));
expect.send("N");
expect.expect(regexp(": $"));
expect.send("\b");
expect.expect(regexp("\\(y\\/n\\)"));
expect.sendLine("y");
expect.expect(contains("Would you like to sign the guestbook?"));
expect.send("n");
expect.expect(contains("[RETURN]"));
expect.sendLine();
} finally {
expect.close();
session.close();
ssh.close();
}
}
示例13: client
import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
public SFTPClient client() throws IOException {
final SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier(new PublicKeyVerifier(hostKey.publicKey()));
ssh.connect("localhost", port);
createdClients.add(ssh);
if (null == password) {
ssh.authPublickey(user, new KeyPairWrapper(keyPair));
} else {
ssh.authPassword(user, password);
}
return ssh.newSFTPClient();
}
示例14: getFilesInPath
import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
public ArrayList< String > getFilesInPath( String path )
{
ArrayList< String > ret = new ArrayList< String >();
SSHClient client = new SSHClient();
client.addHostKeyVerifier(new PromiscuousVerifier());
try {
client.connect(hostName);
client.authPassword(userName, userPass);
SFTPClient sftp = client.newSFTPClient();
List< RemoteResourceInfo > files = sftp.ls( path );
for( RemoteResourceInfo file: files )
{
ret.add( file.getPath() );
}
sftp.close();
client.disconnect();
} catch( Exception e ) {
logger.error( e.toString() );
}
return ret;
}
示例15: login
import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Override
public boolean login(String username, String password) throws AuthenticationException {
try {
logout();
// ssh.authPublickey(System.getProperty("user.name"));
log.info("new SSHClient");
ssh = new SSHClient();
log.info("verify all hosts");
ssh.addHostKeyVerifier(new HostKeyVerifier() {
public boolean verify(String arg0, int arg1, PublicKey arg2) {
return true; // don't bother verifying
}
});
log.info("connecting");
ssh.connect("127.0.0.1");
log.info("authenticating: {}", username);
ssh.authPassword(username, password);
log.info("starting session");
session = ssh.startSession();
log.info("allocating PTY");
session.allocateDefaultPTY();
log.info("starting shell");
shell = session.startShell();
log.info("SSH session established");
this.username = username;
input = new BufferedReader(new InputStreamReader(shell.getInputStream()));
output = shell.getOutputStream();
sender = new SSHSessionOutput(input);
} catch (Exception e) {
log.error(e.getMessage());
finalize();
throw new SSHAuthenticationException(e.getMessage(), e);
}
return true;
}