本文整理了Java中com.jcraft.jsch.JSch.addIdentity()
方法的一些代码示例,展示了JSch.addIdentity()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSch.addIdentity()
方法的具体详情如下:
包路径:com.jcraft.jsch.JSch
类名称:JSch
方法名:addIdentity
[英]Adds an identity to be used for public-key authentication. Before registering it into identityRepository, it will be deciphered with passphrase
.
[中]添加用于公钥身份验证的标识。在将其注册到identityRepository之前,将使用passphrase
对其进行解密。
代码示例来源:origin: apache/incubator-gobblin
@Override
public boolean setIdentity(String privateKey, JSch jsch) {
try {
jsch.addIdentity(privateKey);
log.info("Successfully set identity using local file " + privateKey);
return true;
} catch (Exception e) {
log.warn("Failed to set identity using local file. Will attempt next strategy. " + e.getMessage());
}
return false;
}
}
代码示例来源:origin: apache/kylin
private Session newJSchSession() throws JSchException {
JSch jsch = new JSch();
if (identityPath != null) {
jsch.addIdentity(identityPath);
}
Session session = jsch.getSession(username, hostname, port);
if (password != null) {
session.setPassword(password);
}
session.setConfig("StrictHostKeyChecking", "no");
return session;
}
代码示例来源:origin: apache/incubator-gobblin
@Override
public boolean setIdentity(String privateKey, JSch jsch) {
FileSystem fs;
try {
fs = FileSystem.get(new Configuration());
} catch (Exception e) {
log.warn("Failed to set identity using HDFS file. Will attempt next strategy. " + e.getMessage());
return false;
}
Preconditions.checkNotNull(fs, "FileSystem cannot be null");
try (FSDataInputStream privateKeyStream = fs.open(new Path(privateKey))) {
byte[] bytes = IOUtils.toByteArray(privateKeyStream);
jsch.addIdentity("sftpIdentityKey", bytes, (byte[]) null, (byte[]) null);
log.info("Successfully set identity using HDFS file");
return true;
} catch (Exception e) {
log.warn("Failed to set identity using HDFS file. Will attempt next strategy. " + e.getMessage());
return false;
}
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
private Session createSession(String host, Args args) throws JSchException {
JSch jsch = new JSch();
for (String keyFile : getKeyFiles()) {
jsch.addIdentity(keyFile);
}
JSch.setLogger(new LogAdapter());
Session session = jsch.getSession(args.user, host, args.sshPort);
session.setConfig("StrictHostKeyChecking", "no");
return session;
}
代码示例来源:origin: stackoverflow.com
String privateKey = ".ssh/id_rsa";
jsch.addIdentity(privateKey);
System.out.println("identity added ");
代码示例来源:origin: apache/incubator-gobblin
@Override
protected JSch createDefaultJSch(FS fs) throws JSchException {
if (GitMonitoringService.this.isJschLoggerEnabled) {
JSch.setLogger(new JschLogger());
}
JSch defaultJSch = super.createDefaultJSch(fs);
defaultJSch.getIdentityRepository().removeAll();
if (GitMonitoringService.this.privateKeyPath != null) {
defaultJSch.addIdentity(GitMonitoringService.this.privateKeyPath, GitMonitoringService.this.passphrase);
} else {
defaultJSch.addIdentity("gaas-git", GitMonitoringService.this.privateKey, null,
GitMonitoringService.this.passphrase.getBytes(Charset.forName("UTF-8")));
}
if (!Strings.isNullOrEmpty(GitMonitoringService.this.knownHosts)) {
defaultJSch.setKnownHosts(new ByteArrayInputStream(GitMonitoringService.this.knownHosts.getBytes(Charset.forName("UTF-8"))));
} else if (!Strings.isNullOrEmpty(GitMonitoringService.this.knownHostsFile)) {
defaultJSch.setKnownHosts(GitMonitoringService.this.knownHostsFile);
}
return defaultJSch;
}
};
代码示例来源:origin: apache/usergrid
private void setSession() {
JSch ssh;
// wait until SSH port of remote end comes up
boolean success = waitActive( SESSION_CONNECT_TIMEOUT );
if( ! success ) {
LOG.warn( "Port 22 of {} did not open in time", value.getPublicIpAddress() );
}
// try to open ssh session
try {
Thread.sleep( 30000 );
ssh = new JSch();
ssh.addIdentity( value.getSshKeyFile() );
session = ssh.getSession( Utils.DEFAULT_USER, value.getPublicIpAddress() );
session.setConfig( "StrictHostKeyChecking", "no" );
session.connect();
}
catch ( Exception e ) {
LOG.error( "Error while connecting to ssh session of " + value.getPublicIpAddress(), e );
session = null;
}
}
代码示例来源:origin: apache/nifi
public static Session createSession(final SFTPConfiguration conf, final JSch jsch) throws JSchException, IOException {
if (conf == null || null == jsch) {
throw new NullPointerException();
}
final Hashtable<String, String> newOptions = new Hashtable<>();
Session session = jsch.getSession(conf.username, conf.hostname, conf.port);
final String hostKeyVal = conf.hostkeyFile;
if (null != hostKeyVal) {
try {
jsch.setKnownHosts(hostKeyVal);
} catch (final IndexOutOfBoundsException iob) {
throw new IOException("Unable to establish connection due to bad known hosts key file " + hostKeyVal, iob);
}
} else {
newOptions.put("StrictHostKeyChecking", "no");
session.setConfig(newOptions);
}
final String privateKeyVal = conf.privatekeyFile;
if (null != privateKeyVal) {
jsch.addIdentity(privateKeyVal, conf.privateKeypassphrase);
}
if (null != conf.password) {
session.setPassword(conf.password);
}
session.setTimeout(conf.connectionTimeout); //set timeout for connection
session.connect();
session.setTimeout(conf.dataTimeout); //set timeout for data transfer
return session;
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
jsch.addIdentity(keyFile);
代码示例来源:origin: spring-cloud/spring-cloud-config
@Override
protected Session createSession(Host hc, String user, String host, int port, FS fs) throws JSchException {
if (sshKeysByHostname.containsKey(host)) {
JGitEnvironmentProperties sshUriProperties = sshKeysByHostname.get(host);
jSch.addIdentity(host, sshUriProperties.getPrivateKey().getBytes(), null, null);
if (sshUriProperties.getKnownHostsFile() != null) {
jSch.setKnownHosts(sshUriProperties.getKnownHostsFile());
}
if (sshUriProperties.getHostKey() != null) {
HostKey hostkey = new HostKey(host, Base64.decode(sshUriProperties.getHostKey()));
jSch.getHostKeyRepository().add(hostkey, null);
}
return jSch.getSession(user, host, port);
}
throw new JSchException("no keys configured for hostname " + host);
}
代码示例来源:origin: pentaho/pentaho-kettle
passphrasebytes = GetPrivateKeyPassPhrase().getBytes();
jsch.addIdentity( getUserName(), FileUtil.getContent( KettleVFS.getFileObject( prvkey ) ), // byte[] privateKey
代码示例来源:origin: apache/nifi
jsch.addIdentity(privateKeyFile, ctx.getProperty(PRIVATE_KEY_PASSPHRASE).evaluateAttributeExpressions(flowFile).getValue());
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
private static void loadIdentity(JSch sch, File priv) {
if (priv.isFile()) {
try {
sch.addIdentity(priv.getAbsolutePath());
} catch (JSchException e) {
// Instead, pretend the key doesn't exist.
}
}
}
代码示例来源:origin: apache/ignite
ssh.addIdentity(spec.key().getAbsolutePath());
代码示例来源:origin: KylinOLAP/Kylin
private Session newJSchSession() throws JSchException {
JSch jsch = new JSch();
if (identityPath != null) {
jsch.addIdentity(identityPath);
}
Session session = jsch.getSession(username, hostname, 22);
if (password != null) {
session.setPassword(password);
}
session.setConfig("StrictHostKeyChecking", "no");
return session;
}
代码示例来源:origin: FlowCI/flow-platform
@Override
protected JSch createDefaultJSch(FS fs) throws JSchException {
JSch jSch = super.createDefaultJSch(fs);
// apply customized private key
if (privateKeyPath != null) {
jSch.removeAllIdentity();
jSch.addIdentity(privateKeyPath.toString());
}
return jSch;
}
};
代码示例来源:origin: eBay/parallec
jsch.addIdentity(privKeyAbsPath, sshMeta.getPassphrase());
} else {
jsch.addIdentity(privKeyAbsPath);
代码示例来源:origin: dboissier/mongo4idea
Session session = jsch.getSession(proxyUser, proxyHost);
if (AuthenticationMethod.PRIVATE_KEY.equals(authenticationMethod)) {
jsch.addIdentity(sshTunnelingConfiguration.getPrivateKeyPath(),
sshTunnelingConfiguration.getProxyPassword());
} else {
代码示例来源:origin: dadoonet/fscrawler
private ChannelSftp openSSHConnection(Server server) throws Exception {
logger.debug("Opening SSH connection to {}@{}", server.getUsername(), server.getHostname());
JSch jsch = new JSch();
Session session = jsch.getSession(server.getUsername(), server.getHostname(), server.getPort());
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
if (server.getPemPath() != null) {
jsch.addIdentity(server.getPemPath());
}
session.setConfig(config);
if (server.getPassword() != null) {
session.setPassword(server.getPassword());
}
session.connect();
//Open a new session for SFTP.
Channel channel = session.openChannel("sftp");
channel.connect();
//checking SSH client connection.
if (!channel.isConnected()) {
logger.warn("Cannot connect with SSH to {}@{}", server.getUsername(),
server.getHostname());
throw new RuntimeException("Can not connect to " + server.getUsername() + "@" + server.getHostname());
}
logger.debug("SSH connection successful");
return (ChannelSftp) channel;
}
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
jsch.addIdentity(identityKey);
byIdentityFile.put(identityKey, jsch);
内容来源于网络,如有侵权,请联系作者删除!