Class SshServer
java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.common.util.closeable.IoBaseCloseable
org.apache.sshd.common.util.closeable.AbstractCloseable
org.apache.sshd.common.util.closeable.AbstractInnerCloseable
org.apache.sshd.common.kex.AbstractKexFactoryManager
org.apache.sshd.common.helpers.AbstractFactoryManager
org.apache.sshd.server.SshServer
- All Implemented Interfaces:
Closeable, AutoCloseable, Channel, org.apache.sshd.common.AttributeRepository, org.apache.sshd.common.AttributeStore, org.apache.sshd.common.auth.UserAuthFactoriesManager<ServerSession, UserAuth, UserAuthFactory>, ChannelListenerManager, ChannelStreamWriterResolver, ChannelStreamWriterResolverManager, org.apache.sshd.common.Closeable, FactoryManager, PortForwardingEventListenerManager, org.apache.sshd.common.io.IoServiceEventListenerManager, KexExtensionHandlerManager, KexFactoryManager, org.apache.sshd.common.keyprovider.KeyPairProviderHolder, org.apache.sshd.common.PropertyResolver, ReservedSessionMessagesManager, SessionDisconnectHandlerManager, org.apache.sshd.common.session.SessionHeartbeatController, SessionListenerManager, UnknownChannelReferenceHandlerManager, org.apache.sshd.common.signature.SignatureFactoriesHolder, org.apache.sshd.common.signature.SignatureFactoriesManager, ServerAuthenticationManager, ServerFactoryManager
The SshServer class is the main entry point for the server side of the SSH protocol.
The SshServer has to be configured before being started. Such configuration can be done either using a dependency
injection mechanism (such as the Spring framework) or programmatically. Basic setup is usually done using the
setUpDefaultServer() method, which will known ciphers, macs, channels, etc... Besides this basic setup, a
few things have to be manually configured such as the port number, Factory, the
KeyPairProvider and the PasswordAuthenticator.
Some properties can also be configured using the PropertyResolverUtils updateProperty methods.
start() method and stopped
using the stop() method.- Author:
- Apache MINA SSHD Project
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
org.apache.sshd.common.util.closeable.AbstractCloseable.StateNested classes/interfaces inherited from interface org.apache.sshd.common.AttributeRepository
org.apache.sshd.common.AttributeRepository.AttributeKey<T>Nested classes/interfaces inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
org.apache.sshd.common.session.SessionHeartbeatController.HeartbeatType -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.apache.sshd.common.io.IoAcceptorstatic final List<ServiceFactory> static final org.apache.sshd.common.Factory<SshServer> protected Stringprotected intFields inherited from class AbstractFactoryManager
agentFactory, channelFactories, channelListenerProxy, channelListeners, executor, fileSystemFactory, forwarderFactory, forwardingFilter, globalRequestHandlers, ioServiceFactory, ioServiceFactoryFactory, randomFactory, serviceFactories, sessionListenerProxy, sessionListeners, sessionTimeoutListener, shutdownExecutor, timeoutListenerFuture, tunnelListenerProxy, tunnelListenersFields inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
closeFuture, futureLock, stateFields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
logFields inherited from interface ChannelStreamWriterResolver
NONEFields inherited from interface FactoryManager
DEFAULT_VERSIONFields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected org.apache.sshd.common.io.IoAcceptorprotected SessionFactoryObtain the list of active sessions.Retrieve theCommandFactoryto be used to process commands requests.Retrieve theGSSAuthenticatorto be used by the SSH server.getHost()Retrieve theHostBasedAuthenticatorto be used by the SSH server.org.apache.sshd.common.keyprovider.HostKeyCertificateProviderprotected org.apache.sshd.common.CloseableRetrieve theKeyboardInteractiveAuthenticatorto be used by the SSH server.org.apache.sshd.common.keyprovider.KeyPairProviderRetrieve thePasswordAuthenticatorto be used by the SSH server.intgetPort()Retrieve thePublickeyAuthenticatorto be used by SSH server.Retrieve theShellFactoryobject to be used to create shells.List<? extends SubsystemFactory> Retrieve the list of named factories forCommandFactory.Commandto be used to create subsystems.booleanvoidopen()voidsetCommandFactory(CommandFactory commandFactory) voidsetGSSAuthenticator(GSSAuthenticator gssAuthenticator) voidvoidsetHostBasedAuthenticator(HostBasedAuthenticator hostBasedAuthenticator) voidsetHostKeyCertificateProvider(org.apache.sshd.common.keyprovider.HostKeyCertificateProvider hostKeyCertificateProvider) voidsetKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator interactiveAuthenticator) voidsetKeyPairProvider(org.apache.sshd.common.keyprovider.KeyPairProvider keyPairProvider) voidsetPasswordAuthenticator(PasswordAuthenticator passwordAuthenticator) voidsetPort(int port) Configure the port number to use for this SSH server.voidsetPublickeyAuthenticator(PublickeyAuthenticator publickeyAuthenticator) voidsetSessionFactory(SessionFactory sessionFactory) voidsetShellFactory(ShellFactory shellFactory) voidsetSubsystemFactories(List<? extends SubsystemFactory> subsystemFactories) static SshServerSetup a default servervoidsetUserAuthFactories(List<UserAuthFactory> userAuthFactories) voidstart()Start the SSH server and accept incoming exceptions on the configured port.voidstop()Stop the SSH server.voidstop(boolean immediately) toString()Methods inherited from class AbstractFactoryManager
addChannelListener, addPortForwardingEventListener, addSessionListener, attributeKeys, clearAttributes, computeAttributeIfAbsent, createSessionTimeoutListener, getAgentFactory, getAttribute, getAttributesCount, getChannelFactories, getChannelListenerProxy, getChannelStreamWriterResolver, getFileSystemFactory, getForwarderFactory, getForwardingFilter, getGlobalRequestHandlers, getIoServiceEventListener, getIoServiceFactory, getIoServiceFactoryFactory, getNioWorkers, getParentPropertyResolver, getPortForwardingEventListenerProxy, getProperties, getRandomFactory, getReservedSessionMessagesHandler, getScheduledExecutorService, getServiceFactories, getSessionDisconnectHandler, getSessionListenerProxy, getUnknownChannelReferenceHandler, getVersion, removeAttribute, removeChannelListener, removePortForwardingEventListener, removeSessionListener, removeSessionTimeout, resolveUnknownChannelReferenceHandler, setAgentFactory, setAttribute, setChannelFactories, setChannelStreamWriterResolver, setFileSystemFactory, setForwarderFactory, setForwardingFilter, setGlobalRequestHandlers, setIoServiceEventListener, setIoServiceFactoryFactory, setNioWorkers, setParentPropertyResolver, setRandomFactory, setReservedSessionMessagesHandler, setScheduledExecutorService, setScheduledExecutorService, setServiceFactories, setSessionDisconnectHandler, setUnknownChannelReferenceHandler, setupSessionTimeout, stopSessionTimeoutListenerMethods inherited from class AbstractKexFactoryManager
getCipherFactories, getCompressionFactories, getDelegate, getKexExtensionHandler, getKeyExchangeFactories, getMacFactories, getSignatureFactories, resolveEffectiveFactories, resolveEffectiveProvider, setCipherFactories, setCompressionFactories, setKexExtensionHandler, setKeyExchangeFactories, setMacFactories, setSignatureFactoriesMethods inherited from class org.apache.sshd.common.util.closeable.AbstractInnerCloseable
doCloseGracefully, doCloseImmediatelyMethods inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, preClose, removeCloseFutureListenerMethods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warnMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.sshd.common.AttributeRepository
attributeKeys, getAttribute, getAttributesCountMethods inherited from interface org.apache.sshd.common.AttributeStore
clearAttributes, computeAttributeIfAbsent, removeAttribute, setAttributeMethods inherited from interface ChannelListenerManager
addChannelListener, getChannelListenerProxy, removeChannelListenerMethods inherited from interface ChannelStreamWriterResolverManager
getChannelStreamWriterResolver, resolveChannelStreamWriter, resolveChannelStreamWriterResolver, setChannelStreamWriterResolverMethods inherited from interface org.apache.sshd.common.Closeable
close, isOpenMethods inherited from interface FactoryManager
getAgentFactory, getAgentForwardingFilter, getChannelFactories, getFileSystemFactory, getForwarderFactory, getForwardingFilter, getGlobalRequestHandlers, getIoServiceFactory, getRandomFactory, getScheduledExecutorService, getServiceFactories, getTcpForwardingFilter, getVersion, getX11ForwardingFilter, resolveAttributeMethods inherited from interface org.apache.sshd.common.io.IoServiceEventListenerManager
getIoServiceEventListener, setIoServiceEventListenerMethods inherited from interface KexExtensionHandlerManager
getKexExtensionHandler, setKexExtensionHandlerMethods inherited from interface KexFactoryManager
getCipherFactories, getCipherFactoriesNameList, getCipherFactoriesNames, getCompressionFactories, getCompressionFactoriesNameList, getCompressionFactoriesNames, getKeyExchangeFactories, getMacFactories, getMacFactoriesNameList, getMacFactoriesNames, setCipherFactories, setCipherFactoriesNameList, setCipherFactoriesNames, setCipherFactoriesNames, setCompressionFactories, setCompressionFactoriesNameList, setCompressionFactoriesNames, setCompressionFactoriesNames, setKeyExchangeFactories, setMacFactories, setMacFactoriesNameList, setMacFactoriesNames, setMacFactoriesNamesMethods inherited from interface PortForwardingEventListenerManager
addPortForwardingEventListener, getPortForwardingEventListenerProxy, removePortForwardingEventListenerMethods inherited from interface org.apache.sshd.common.PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty, isEmptyMethods inherited from interface ReservedSessionMessagesManager
getReservedSessionMessagesHandler, setReservedSessionMessagesHandlerMethods inherited from interface ServerAuthenticationManager
setUserAuthFactoriesNamesMethods inherited from interface SessionDisconnectHandlerManager
getSessionDisconnectHandler, setSessionDisconnectHandlerMethods inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
disableSessionHeartbeat, getSessionHeartbeatInterval, getSessionHeartbeatType, setSessionHeartbeat, setSessionHeartbeatMethods inherited from interface SessionListenerManager
addSessionListener, getSessionListenerProxy, removeSessionListenerMethods inherited from interface org.apache.sshd.common.signature.SignatureFactoriesHolder
getSignatureFactories, getSignatureFactoriesNameList, getSignatureFactoriesNamesMethods inherited from interface org.apache.sshd.common.signature.SignatureFactoriesManager
setSignatureFactories, setSignatureFactoriesNameList, setSignatureFactoriesNames, setSignatureFactoriesNamesMethods inherited from interface UnknownChannelReferenceHandlerManager
getUnknownChannelReferenceHandler, resolveUnknownChannelReferenceHandler, setUnknownChannelReferenceHandlerMethods inherited from interface org.apache.sshd.common.auth.UserAuthFactoriesManager
getUserAuthFactoriesNameList, getUserAuthFactoriesNames, setUserAuthFactoriesNameList, setUserAuthFactoriesNames
-
Field Details
-
DEFAULT_SSH_SERVER_FACTORY
-
DEFAULT_SERVICE_FACTORIES
-
acceptor
protected org.apache.sshd.common.io.IoAcceptor acceptor -
host
-
port
protected int port
-
-
Constructor Details
-
SshServer
public SshServer()
-
-
Method Details
-
getHost
-
setHost
-
getPort
public int getPort() -
setPort
public void setPort(int port) Configure the port number to use for this SSH server.- Parameters:
port- the port number for this SSH server
-
getBoundAddresses
-
getUserAuthFactories
- Specified by:
getUserAuthFactoriesin interfaceorg.apache.sshd.common.auth.UserAuthFactoriesManager<ServerSession, UserAuth, UserAuthFactory>
-
setUserAuthFactories
- Specified by:
setUserAuthFactoriesin interfaceorg.apache.sshd.common.auth.UserAuthFactoriesManager<ServerSession, UserAuth, UserAuthFactory>
-
getShellFactory
Description copied from interface:ServerFactoryManagerRetrieve theShellFactoryobject to be used to create shells.- Specified by:
getShellFactoryin interfaceServerFactoryManager- Returns:
- a valid
ShellFactoryobject ornullif shells are not supported on this server
-
setShellFactory
-
getSessionFactory
-
setSessionFactory
-
getCommandFactory
Description copied from interface:ServerFactoryManagerRetrieve theCommandFactoryto be used to process commands requests.- Specified by:
getCommandFactoryin interfaceServerFactoryManager- Returns:
- A valid
CommandFactoryobject ornullif commands are not supported on this server
-
setCommandFactory
-
getSubsystemFactories
Description copied from interface:ServerFactoryManagerRetrieve the list of named factories forCommandFactory.Commandto be used to create subsystems.- Specified by:
getSubsystemFactoriesin interfaceServerFactoryManager- Returns:
- a list of named
SubsystemFactory-ies ornull/empty if subsystems are not supported on this server
-
setSubsystemFactories
-
getPasswordAuthenticator
Description copied from interface:ServerAuthenticationManagerRetrieve thePasswordAuthenticatorto be used by the SSH server. If no authenticator has been configured (i.e. this method returnsnull), then client authentication requests based on passwords will be rejected.- Specified by:
getPasswordAuthenticatorin interfaceServerAuthenticationManager- Returns:
- the
PasswordAuthenticatorornull
-
setPasswordAuthenticator
- Specified by:
setPasswordAuthenticatorin interfaceServerAuthenticationManager
-
getPublickeyAuthenticator
Description copied from interface:ServerAuthenticationManagerRetrieve thePublickeyAuthenticatorto be used by SSH server. If no authenticator has been configured (i.e. this method returnsnull), then client authentication requests based on keys will be rejected.- Specified by:
getPublickeyAuthenticatorin interfaceServerAuthenticationManager- Returns:
- the
PublickeyAuthenticatorornull
-
setPublickeyAuthenticator
- Specified by:
setPublickeyAuthenticatorin interfaceServerAuthenticationManager
-
getKeyboardInteractiveAuthenticator
Description copied from interface:ServerAuthenticationManagerRetrieve theKeyboardInteractiveAuthenticatorto be used by the SSH server. If no authenticator has been configured (i.e. this method returnsnull), then client authentication requests based on this method will be rejected.- Specified by:
getKeyboardInteractiveAuthenticatorin interfaceServerAuthenticationManager- Returns:
- The
KeyboardInteractiveAuthenticatorornull
-
setKeyboardInteractiveAuthenticator
public void setKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator interactiveAuthenticator) - Specified by:
setKeyboardInteractiveAuthenticatorin interfaceServerAuthenticationManager
-
getGSSAuthenticator
Description copied from interface:ServerAuthenticationManagerRetrieve theGSSAuthenticatorto be used by the SSH server. If no authenticator has been configured (i.e. this method returnsnull), then client authentication requests based on gssapi will be rejected.- Specified by:
getGSSAuthenticatorin interfaceServerAuthenticationManager- Returns:
- the
GSSAuthenticatorornull
-
setGSSAuthenticator
- Specified by:
setGSSAuthenticatorin interfaceServerAuthenticationManager
-
getHostBasedAuthenticator
Description copied from interface:ServerAuthenticationManagerRetrieve theHostBasedAuthenticatorto be used by the SSH server. If no authenticator has been configured (i.e. this method returnsnull), then client authentication requests based on this method will be rejected.- Specified by:
getHostBasedAuthenticatorin interfaceServerAuthenticationManager- Returns:
- the
HostBasedAuthenticatorornull
-
setHostBasedAuthenticator
- Specified by:
setHostBasedAuthenticatorin interfaceServerAuthenticationManager
-
getKeyPairProvider
public org.apache.sshd.common.keyprovider.KeyPairProvider getKeyPairProvider()- Specified by:
getKeyPairProviderin interfaceorg.apache.sshd.common.keyprovider.KeyPairProviderHolder
-
setKeyPairProvider
public void setKeyPairProvider(org.apache.sshd.common.keyprovider.KeyPairProvider keyPairProvider) - Specified by:
setKeyPairProviderin interfaceorg.apache.sshd.common.keyprovider.KeyPairProviderHolder
-
getHostKeyCertificateProvider
public org.apache.sshd.common.keyprovider.HostKeyCertificateProvider getHostKeyCertificateProvider()- Specified by:
getHostKeyCertificateProviderin interfaceServerAuthenticationManager- Returns:
- a
HostKeyCertificateProviderif available, null as default
-
setHostKeyCertificateProvider
public void setHostKeyCertificateProvider(org.apache.sshd.common.keyprovider.HostKeyCertificateProvider hostKeyCertificateProvider) - Specified by:
setHostKeyCertificateProviderin interfaceServerAuthenticationManager
-
checkConfig
protected void checkConfig()- Overrides:
checkConfigin classAbstractFactoryManager
-
isStarted
public boolean isStarted() -
start
Start the SSH server and accept incoming exceptions on the configured port. Ignored if alreadystarted- Throws:
IOException- If failed to start
-
stop
Stop the SSH server. This method will block until all resources are actually disposed.- Throws:
IOException- if stopping failed somehow
-
stop
- Throws:
IOException
-
open
- Throws:
IOException
-
getInnerCloseable
protected org.apache.sshd.common.Closeable getInnerCloseable()- Specified by:
getInnerCloseablein classorg.apache.sshd.common.util.closeable.AbstractInnerCloseable
-
getActiveSessions
Obtain the list of active sessions.- Returns:
- A
Listof the currently active session
-
createAcceptor
protected org.apache.sshd.common.io.IoAcceptor createAcceptor() -
createSessionFactory
-
toString
-
setUpDefaultServer
-