You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "tomaswolf (via GitHub)" <gi...@apache.org> on 2023/09/28 20:47:08 UTC
[GitHub] [mina-sshd] tomaswolf commented on issue #421: Add complete example for running an SSH server
tomaswolf commented on issue #421:
URL: https://github.com/apache/mina-sshd/issues/421#issuecomment-1739981592
A server example _does_ exist at [SshServerMain](https://github.com/apache/mina-sshd/blob/master/sshd-cli/src/main/java/org/apache/sshd/cli/server/SshServerMain.java). Note that it is insecure: it allows any password log-in where the password equals the user name given, and it accepts any public key.
If you want it even simpler: here's a quick'n'dirty hack I sometimes use for testing:
```
import java.nio.file.Paths;
import java.time.Duration;
import org.apache.sshd.common.session.SessionHeartbeatController;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.forward.AcceptAllForwardingFilter;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.shell.InteractiveProcessShellFactory;
public class TestServer {
public static void main(String[] args) throws Exception {
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(12133);
SimpleGeneratorHostKeyProvider hostKeys = new SimpleGeneratorHostKeyProvider(Paths.get("/tmp/a.ser"));
sshd.setShellFactory(InteractiveProcessShellFactory.INSTANCE);
sshd.setSessionHeartbeat(SessionHeartbeatController.HeartbeatType.IGNORE, Duration.ofSeconds(5));
sshd.setKeyPairProvider(hostKeys);
hostKeys.loadKeys(null);
sshd.setPasswordAuthenticator((username, password, session) -> true);
sshd.setPublickeyAuthenticator((username, pubkey, session) -> true);
sshd.setForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
sshd.start();
Thread.sleep(10000000);
}
}
```
Listens on port 12133 and allows any password or public key.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org