Java Code Examples for org.apache.sshd.server.PasswordAuthenticator

The following examples show how to use org.apache.sshd.server.PasswordAuthenticator. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: ExpectIt   Source File:    License: Apache License 2.0 6 votes vote down vote up
public static void startSshServer() throws IOException {
    sshServer = SshServer.setUpDefaultServer();
    ServerSocket serverSocket = new ServerSocket(0);
    sshPort = serverSocket.getLocalPort();
            new PasswordAuthenticator() {
                public boolean authenticate(
                        String username,
                        String password,
                        ServerSession session) {
                    return "ssh".equals(username) && "secret".equals(password);
    sshServer.setShellFactory(new SshEchoCommandFactory());
    sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
Example 2
Source Project: gameserver   Source File:    License: Apache License 2.0 5 votes vote down vote up
public void startServer(String bindAddr, int port) {
	try {
		sshd = SshServer.setUpDefaultServer();
		SimpleGeneratorHostKeyProvider provider = new SimpleGeneratorHostKeyProvider("hostkey.ser", "RSA", 4096);
		EnumSet<ProcessShellFactory.TtyOptions> options = EnumSet.allOf(ProcessShellFactory.TtyOptions.class);
		sshd.setShellFactory(new ProcessShellFactory(new String[] { "/bin/bash", "-i" }, options));
    sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
      public boolean authenticate(String username, String password, ServerSession session) {
          return username != null && password.equals("VpWk5ujKA1c");
		sshd.start();"AdminServer bind at " + bindAddr + ":" + port);
	} catch (Exception e) {
		logger.warn("Failed to start AdminServer", e);