当前位置: 首页>>代码示例>>Java>>正文


Java Connection.authenticateWithPublicKey方法代码示例

本文整理汇总了Java中ch.ethz.ssh2.Connection.authenticateWithPublicKey方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.authenticateWithPublicKey方法的具体用法?Java Connection.authenticateWithPublicKey怎么用?Java Connection.authenticateWithPublicKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ch.ethz.ssh2.Connection的用法示例。


在下文中一共展示了Connection.authenticateWithPublicKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: SSHConnection

import ch.ethz.ssh2.Connection; //导入方法依赖的package包/类
/**
   * SSHConnection authenticate using a user and and a public key
   * @param hostname  The host to connect to
   * @param username  The user name
   * @param keyfile  The certificate public key file
   * @throws IOException
   */
  public SSHConnection(String hostname, String username, File keyfile) throws IOException {
String keyfilePass = ""; // will be ignored if not needed

      /* Create a connection instance */
      connection = new Connection(hostname);

      /* Now connect */
      connection.connect();

      /* Authenticate */        
      boolean isAuthenticated = connection.authenticateWithPublicKey(username, keyfile, keyfilePass);

      if (isAuthenticated == false)
          throw new IOException("Authentication failed.");
  }
 
开发者ID:cloudezz,项目名称:harmony,代码行数:23,代码来源:SSHConnection.java

示例2: login

import ch.ethz.ssh2.Connection; //导入方法依赖的package包/类
/**
 * Attempt to login to host
 * @param host host name/ip
 * @param user user name
 * @param aFile key file
 * @param pwd password for the key file ("" if none)
 * @throws IOException
 */
public void login(String host, String user, File aFile, String pwd ) throws IOException {
    setParams(host, user, pwd, aFile);
    if( !aFile.exists()){
        throw  new IOException("Cant read key file " + aFile.getAbsolutePath());
    }
    conn = new Connection(host);
    info = conn.connect();
    
    if(!conn.authenticateWithPublicKey(user, aFile, pwd)){
        throw  new IOException("Cant authenticate with user " + user + " and password " + pwd);
    }
}
 
开发者ID:lesavsoftware,项目名称:rem-adb-exec,代码行数:21,代码来源:SSHConnection.java

示例3: main

import ch.ethz.ssh2.Connection; //导入方法依赖的package包/类
public static void main(String[] args)
{
	String hostname = "127.0.0.1";
	String username = "joe";

	File keyfile = new File("~/.ssh/id_rsa"); // or "~/.ssh/id_dsa"
	String keyfilePass = "joespass"; // will be ignored if not needed

	try
	{
		/* Create a connection instance */

		Connection conn = new Connection(hostname);

		/* Now connect */

		conn.connect();

		/* Authenticate */

		boolean isAuthenticated = conn.authenticateWithPublicKey(username, keyfile, keyfilePass);

		if (isAuthenticated == false)
			throw new IOException("Authentication failed.");

		/* Create a session */

		Session sess = conn.openSession();

		sess.execCommand("uname -a && date && uptime && who");

		InputStream stdout = new StreamGobbler(sess.getStdout());

		BufferedReader br = new BufferedReader(new InputStreamReader(stdout));

		System.out.println("Here is some information about the remote host:");

		while (true)
		{
			String line = br.readLine();
			if (line == null)
				break;
			System.out.println(line);
		}

		/* Close this session */
		
		sess.close();

		/* Close the connection */

		conn.close();

	}
	catch (IOException e)
	{
		e.printStackTrace(System.err);
		System.exit(2);
	}
}
 
开发者ID:dreajay,项目名称:jcode,代码行数:61,代码来源:PublicKeyAuthentication.java


注:本文中的ch.ethz.ssh2.Connection.authenticateWithPublicKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。