@Override public Command createCommand(String command) { return new ProcessShellFactory(command.split(" ")).create(); } });
private SshServer defaultSshServer() { SshServer sshServer = SshServer.setUpDefaultServer(); sshServer.setPort(randomPort()); ClassLoadableResourceKeyPairProvider fileKeyPairProvider = new ClassLoadableResourceKeyPairProvider(hostkey); sshServer.setKeyPairProvider(fileKeyPairProvider); sshServer.setPasswordAuthenticator(new PasswordAuthenticator() { @Override public boolean authenticate(String username, String password, ServerSession session) { return username.equals(password); } }); sshServer.setGSSAuthenticator(new BogusGSSAuthenticator()); sshServer.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory())); ScpCommandFactory commandFactory = new ScpCommandFactory(); commandFactory.setDelegateCommandFactory(new CommandFactory() { @Override public Command createCommand(String command) { return new ProcessShellFactory(command.split(" ")).create(); } }); sshServer.setCommandFactory(commandFactory); sshServer.setShellFactory(new ProcessShellFactory("ls")); return sshServer; }
sshd.setCommandFactory(new CommandFactory() { public Command createCommand(String command) { return new ProcessShellFactory(" ")).create(); } });
@Override public Command createCommand(String command) { Factory<Command> factory = new ProcessShellFactory(GenericUtils.split(command, ' ')); return factory.create(); } }
@Override public Command createCommand(String command) { Factory<Command> factory = new ProcessShellFactory(GenericUtils.split(command, ' ')); return factory.create(); } }
public EmbeddedSSHServer(Path homeDir, int port) { this.sshServer = SshServer.setUpDefaultServer(); this.sshServer.setPort(port); this.sshServer.setCommandFactory(new EchoCommandFactory()); this.sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()); this.sshServer.setPasswordAuthenticator((username, password, serverSession) -> username.equals("admin") && password.equals("admin")); this.sshServer.setPublickeyAuthenticator((s, publicKey, serverSession) -> true); this.homeDir = homeDir; if (EnvironmentUtils.isWindows()) { sshServer.setShellFactory(new ProcessShellFactory(new String[] { "cmd.exe " })); } else { sshServer.setShellFactory(new ProcessShellFactory(new String[] { "/bin/sh", "-i", "-s" })); } }
public EmbeddedSSHServer(Path homeDir, int port) { this.sshServer = SshServer.setUpDefaultServer(); this.sshServer.setPort(port); this.sshServer.setCommandFactory(new EchoCommandFactory()); this.sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()); this.sshServer.setPasswordAuthenticator((username, password, serverSession) -> username.equals("admin") && password.equals("admin")); this.sshServer.setPublickeyAuthenticator((s, publicKey, serverSession) -> true); this.homeDir = homeDir; if (EnvironmentUtils.isWindows()) { sshServer.setShellFactory(new ProcessShellFactory(new String[] { "cmd.exe " })); } else { sshServer.setShellFactory(new ProcessShellFactory(new String[] { "/bin/sh", "-i", "-s" })); } }
@Override public void initialize(int port) { Security.addProvider(new BouncyCastleProvider()); sshd = SshServer.setUpDefaultServer(); sshd.setPort(port); StreamKeyPairProvider fileKeyPairProvider = new StreamKeyPairProvider(); sshd.setKeyPairProvider(fileKeyPairProvider); SftpSubsystem.Factory factory = new SftpSubsystem.Factory(); sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(factory)); sshd.setCommandFactory(new ScpCommandFactory()); sshd.setShellFactory(new ProcessShellFactory()); sshd.setPasswordAuthenticator(new MockPasswordAuthenticator()); }
public void startSSHServer() { int port = 8888; SshServer sshd = SshServer.setUpDefaultServer(); sshd.setPort(port); sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider( "src/test/resources/hostkey.ser")); sshd.setSubsystemFactories(Arrays .<NamedFactory<Command>> asList(new SftpSubsystem.Factory())); sshd.setCommandFactory(new ScpCommandFactory()); sshd.setShellFactory(new ProcessShellFactory(new String[] { "/system/bin/sh", "-i", "-l" })); // necessary if you want to type commands over ssh sshd.setPasswordAuthenticator(new PasswordAuthenticator() { @Override public boolean authenticate(String u, String p, ServerSession s) { return ("sftptest".equals(u) && "sftptest".equals(p)); } }); try { sshd.start(); } catch (IOException e) { e.printStackTrace(); } }
.<NamedFactory<Command>> asList(new SftpSubsystem.Factory())); sshd.setCommandFactory(new ScpCommandFactory()); sshd.setShellFactory(new ProcessShellFactory(new String[] { "/system/bin/sh", "-i", "-l" })); // necessary if you want to type commands over ssh sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
public SSHD() { try { keyPair = KeyPairGenerator.getInstance("RSA").generateKeyPair(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } sshd = SshServer.setUpDefaultServer(); sshd.setKeyPairProvider(new MyKeyPairProvider(keyPair)); sshd.setShellFactory( new ProcessShellFactory( "/bin/sh", "-i")); sshd.setCommandFactory( command -> new ProcessShellFactory( new String[] { "/bin/sh", "-c", command }).create()); }
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("key.ser")); sshd.setShellFactory(new ProcessShellFactory(new String[] { "cmd.exe "}));
new ProcessShellFactory( new String[]{ "/bin/sh", "-i", "-l" } ); sshd.setShellFactory( processShellFactory );
new ProcessShellFactory( new String[]{ "/bin/sh", "-i", "-l" } ); sshd.setShellFactory( processShellFactory );