public class SshdSessionFactory extends SshSessionFactory implements Closeable
SshSessionFactory that uses Apache MINA sshd.| Constructor and Description |
|---|
SshdSessionFactory()
Creates a new
SshdSessionFactory without key cache and a
DefaultProxyDataFactory. |
SshdSessionFactory(KeyCache keyCache,
ProxyDataFactory proxies)
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
protected KeyPasswordProvider |
createKeyPasswordProvider(CredentialsProvider provider)
Creates a
KeyPasswordProvider for a new session. |
protected List<Path> |
getDefaultIdentities(File sshDir)
Gets a list of default identities, i.e., private key files that shall
always be tried for public key authentication.
|
protected List<Path> |
getDefaultKnownHostsFiles(File sshDir)
Gets the list of default user known hosts files.
|
protected String |
getDefaultPreferredAuthentications()
Gets the list of default preferred authentication mechanisms.
|
File |
getHomeDirectory()
Retrieves the global user home directory
|
protected KeyCache |
getKeyCache()
Obtains the
KeyCache to use to cache loaded keys. |
SshdSession |
getSession(URIish uri,
CredentialsProvider credentialsProvider,
FS fs,
int tms)
Open (or reuse) a session to a host.
|
File |
getSshDirectory()
Retrieves the global .ssh directory
|
void |
setHomeDirectory(File homeDir)
Set a global directory to use as the user's home directory
|
void |
setSshDirectory(File sshDir)
Set a global directory to use as the .ssh directory
|
getInstance, getLocalUserName, releaseSession, setInstancepublic SshdSessionFactory()
SshdSessionFactory without key cache and a
DefaultProxyDataFactory.public SshdSessionFactory(KeyCache keyCache, ProxyDataFactory proxies)
SshdSessionFactory using the given KeyCache
and ProxyDataFactory. The keyCache is used for all sessions
created through this session factory; cached keys are destroyed when the
session factory is closed.
Caching ssh keys in memory for an extended period of time is generally
considered bad practice, but there may be circumstances where using a
KeyCache is still the right choice, for instance to avoid that a
user gets prompted several times for the same password for the same key.
In general, however, it is preferable not to use a key cache but
to use a KeyPasswordProvider that has access to some secure storage and can save
and retrieve passwords from there without user interaction. Another
approach is to use an ssh agent.
Note that the underlying ssh library (Apache MINA sshd) may or may not
keep ssh keys in memory for unspecified periods of time irrespective of
the use of a KeyCache.
keyCache - KeyCache to use for caching ssh keys, or null
to not use a key cacheproxies - ProxyDataFactory to use, or null to not use a
proxy database (in which case connections through proxies will
not be possible)public SshdSession getSession(URIish uri, CredentialsProvider credentialsProvider, FS fs, int tms) throws TransportException
SshSessionFactoryA reasonable UserInfo that can interact with the end-user (if necessary) is installed on the returned session by this method.
The caller must connect the session by invoking connect() if
it has not already been connected.
getSession in class SshSessionFactoryuri - URI information about the remote hostcredentialsProvider - provider to support authentication, may be null.fs - the file system abstraction which will be necessary to perform
certain file system operations.tms - Timeout value, in milliseconds.TransportException - the session could not be created.public void close()
close in interface Closeableclose in interface AutoCloseablepublic void setHomeDirectory(@NonNull File homeDir)
homeDir - to usepublic File getHomeDirectory()
null if not setpublic void setSshDirectory(@NonNull File sshDir)
sshDir - to usepublic File getSshDirectory()
null if not set@NonNull protected List<Path> getDefaultKnownHostsFiles(@NonNull File sshDir)
UserKnownHostsFile overrides this default.sshDir - @NonNull protected List<Path> getDefaultIdentities(@NonNull File sshDir)
SshConstants.DEFAULT_IDENTITIES.sshDir - the directory that represents ~/.ssh/protected final KeyCache getKeyCache()
KeyCache to use to cache loaded keys.KeyCache, or null if none.@NonNull protected KeyPasswordProvider createKeyPasswordProvider(CredentialsProvider provider)
KeyPasswordProvider for a new session.provider - the CredentialsProvider to delegate to for user
interactionsKeyPasswordProviderprotected String getDefaultPreferredAuthentications()
null is returned the openssh default list will be in effect. If
the ssh config defines PreferredAuthentications the value from
the ssh config takes precedence.null if
noneCopyright © 2018 Eclipse JGit Project. All rights reserved.