Skip to content

Commit

Permalink
Added support for default identity file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Razvan Rotaru committed Oct 14, 2016
1 parent 7323a73 commit 1a5edff
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package com.mucommander.commons.file.impl.sftp;

import java.io.File;
import java.io.IOException;

import org.slf4j.Logger;
Expand All @@ -41,6 +42,8 @@
class SFTPConnectionHandler extends ConnectionHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(SFTPConnectionHandler.class);

private static final String DEFAULT_IDENTITY_FILE = System.getProperty("user.home")+"/.ssh/id_rsa";

Session session;
ChannelSftp channelSftp;

Expand Down Expand Up @@ -85,6 +88,16 @@ public void startConnection() throws IOException {
jsch.addIdentity(privateKeyPath);
}

if (new File(DEFAULT_IDENTITY_FILE).exists()) {
try {
jsch.addIdentity(DEFAULT_IDENTITY_FILE);
LOGGER.info("Using {} authentication method", PUBLIC_KEY_AUTH_METHOD);
}
catch (JSchException e) {
LOGGER.debug("Unable to load key {}", DEFAULT_IDENTITY_FILE);
}
}

session = jsch.getSession(credentials.getLogin(), realm.getHost(), port);
session.setUserInfo(new PasswordAuthentication());

Expand Down

0 comments on commit 1a5edff

Please sign in to comment.