我需要限制 apache SshServer 中每个用户允许的并发会话。我发现了两个对此功能的引用,但它们似乎已过时。
这是 2010 年的原始补丁:https :
//issues.apache.org/jira/browse/SSHD-95
我还找到了对其用法的参考:http :
//apache-mina.10907.n7.nabble.com/ How-to-set-max-count-connections-in-sshd-service-td44764.html
其中指的是 SshServer.setProperty() 方法。我正在使用 sshd-core 2.4.0,而 SshServer 中没有这种方法,我看不到任何明显的替代品,也找不到任何关于它发生了什么或我应该如何做的文档现在这个。我仍然在 ServerFactoryManager 中看到 MAX_CONCURRENT_SESSIONS 键,所以我认为该功能仍然存在于某处,但我找不到需要设置它的位置。
这是服务器设置的样子(它用于 SFTP 服务器,但这对于 ahnd 的问题应该无关紧要,我想):
private val server = SshServer.setUpDefaultServer().apply {
val sftpSubsystemFactory = SftpSubsystemFactory().apply {
addSftpEventListener(sftpEventListener)
}
port = sftpPort
host = "localhost"
keyPairProvider = when {
sftpKeyname.isEmpty() -> throw IllegalStateException("No key name for SFTP, aborting!")
sftpKeyname == "NO_RSA" -> {
log.warn("Explicitly using NO_RSA, sftp encryption is insecure!")
SimpleGeneratorHostKeyProvider(File("host.ser").toPath())
}
else -> KeyPairProvider.wrap(loadKeyPair(sftpKeyname)) …Run Code Online (Sandbox Code Playgroud) 我正在使用 apache mina sshd 来生成一个 ssh 服务器,以便用户能够远程访问特定系统。
这是我的代码的一部分:
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(830);
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));
sshd.setShellFactory(new ProcessShellFactory(new String[] { "/bin/sh", "-i", "-l" }));
sshd.setCommandFactory(new ScpCommandFactory());
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
public boolean authenticate(String username, String password, ServerSession session) {
return true;
// just to make sure everything is right
// this will implement later
}
});
sshd.start();
Run Code Online (Sandbox Code Playgroud)
在 Windows 上运行此代码时,此代码看起来没问题,但在 Linux (Ubuntu 18.04) 上,出现此错误:
Exception in thread "main" java.net.SocketException: Permission denied
at java.base/sun.nio.ch.Net.bind0(Native Method)
at java.base/sun.nio.ch.Net.bind(Net.java:455)
at java.base/sun.nio.ch.Net.bind(Net.java:447)
at java.base/sun.nio.ch.AsynchronousServerSocketChannelImpl.bind(AsynchronousServerSocketChannelImpl.java:164)
at org.apache.sshd.common.io.nio2.Nio2Acceptor.bind(Nio2Acceptor.java:59) …Run Code Online (Sandbox Code Playgroud)