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; }
private void configureServerForSshOnly(SshServer server) { server.setCommandFactory(sshCommandFactory(null)); }
public void setupSftp() { this.sshServer.setCommandFactory(new ScpCommandFactory()); this.sshServer.setSubsystemFactories(Arrays.asList(new SftpSubsystemFactory())); }
public void setupSftp() { this.sshServer.setCommandFactory(new ScpCommandFactory()); this.sshServer.setSubsystemFactories(Arrays.asList(new SftpSubsystemFactory())); }
private void initSftp() { sshServer.setCommandFactory(new ScpCommandFactory()); sshServer.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory())); }
@Bean public SshServer sshServer() { SshServer server = SshServer.setUpDefaultServer(); server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(properties.getHostKeyFile())); server.setPublickeyAuthenticator(RejectAllPublickeyAuthenticator.INSTANCE); server.setHost(properties.getHost()); String password = properties.getPassword(); if (password == null) { password = UUID.randomUUID().toString(); LOGGER.info(" --- Generating password for ssh connection: {}", password); } final String finalPassword = password; server.setPasswordAuthenticator((username, pass, serverSession) -> username.equals("user") && pass.equals(finalPassword)); server.setPort(properties.getPort()); server.setShellFactory(() -> shellCommandFactory); server.setCommandFactory(command -> shellCommandFactory); return server; }
protected void setupScp() { sshd.setCommandFactory(new ScpCommandFactory()); sshd.setFileSystemFactory(new SecureFileSystemFactory(db)); sshd.setTcpipForwardingFilter(null); sshd.setAgentFactory(null); }
private static SshServer createServer(int port, String repository) { SshServer s = SshServer.setUpDefaultServer(); s.setPort(port); s.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()); s.setPublickeyAuthenticator((username, key, session) -> true); s.setCommandFactory(new GitPackCommandFactory(repository)); return s; } }
private void configureSshdServer(SftpSubsystemFactory factory) { sshdServer.setPort(port); sshdServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser"))); sshdServer.setSubsystemFactories(asList(factory)); sshdServer.setCommandFactory(new ScpCommandFactory()); }
private void configureServerForSshAndFileTransfer(SshServer server) { server.setCommandFactory(sshAndScpCommandFactory()); server.setFileSystemFactory(new SshdNativeFileSystemFactory(properties.getFilesystem().getBase().getDir())); server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList( new SftpSubsystemFactory.Builder().build())); }
@Override protected void before() throws Throwable { sshd = SshServer.setUpDefaultServer(); sshd.setPort(findRandomOpenPortOnAllLocalInterfaces()); sshd.setKeyPairProvider( new ClassLoadableResourceKeyPairProvider(getClass().getClassLoader(), "server_key")); sshd.setCommandFactory(new ScpCommandFactory()); sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory())); sshd.setUserAuthFactories(Collections.singletonList(new UserAuthPublicKeyFactory())); sshd.setHost("localhost"); sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE); sshd.setHostBasedAuthenticator(new StaticHostBasedAuthenticator(true)); VirtualFileSystemFactory fileSystemFactory = new VirtualFileSystemFactory(); fileSystemFactory.setDefaultHomeDir(currentFolder.get().toPath()); sshd.setFileSystemFactory(fileSystemFactory); sshd.start(); }
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" })); } }
private void start() throws IOException { server = serverBuilder.get(); server.setPort(port); server.setHost(ip); server.setShellFactory(new ShellFactoryImpl(shell)); server.setCommandFactory(new ScpCommandFactory.Builder() .withDelegate(command -> new ShellCommand(execute, command)).build()); server.setSubsystemFactories(Collections.singletonList( new SftpSubsystemFactory.Builder().build() )); server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()); server.start(); }
private void start() throws IOException { server = serverBuilder.get(); server.setPort(port); server.setHost(ip); server.setShellFactory(new ShellFactoryImpl(shell)); server.setCommandFactory(new ScpCommandFactory.Builder() .withDelegate(command -> new ShellCommand(execute, command)).build()); server.setSubsystemFactories(Collections.singletonList( new SftpSubsystemFactory.Builder().build() )); server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()); server.start(); }
/** * Construct ssh server thanks to ssh shell properties * * @return ssh server */ @Bean public SshServer sshServer() { SshServer server = SshServer.setUpDefaultServer(); server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(properties.getHostKeyFile())); server.setPublickeyAuthenticator(RejectAllPublickeyAuthenticator.INSTANCE); server.setHost(properties.getHost()); server.setPasswordAuthenticator(passwordAuthenticator); server.setPort(properties.getPort()); server.setShellFactory(() -> shellCommandFactory); server.setCommandFactory(command -> shellCommandFactory); return server; }
@Override protected void startService() throws Exception { String username=cfg.get("auth-username","admin"); String authorizedKeysFilename=cfg.get("authorized-keys-file","cfg/authorized_keys"); String hostKeys=cfg.get("hostkeys-file","cfg/hostkeys.ser"); int port=cfg.getInt("port",2222); checkAuthorizedKeys(authorizedKeysFilename); String[] prefixes= getPrefixes(); sshd = SshServer.setUpDefaultServer(); sshd.setPort(port); sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File(hostKeys))); CliShellFactory csf = new CliShellFactory(getServer(), prefixes); sshd.setShellFactory(csf); sshd.setCommandFactory(csf); sshd.setUserAuthFactories(Collections.singletonList(new UserAuthPublicKeyFactory())); sshd.setPublickeyAuthenticator(new AuthorizedKeysFileBasedPKA(username, authorizedKeysFilename)); sshd.start(); log.info("Started SSHD @ port "+port); }
public static SshServer setupTestServer(Class<?> anchor) { SshServer sshd = SshServer.setUpDefaultServer(); sshd.setKeyPairProvider(createTestHostKeyProvider(anchor)); sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE); sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE); sshd.setShellFactory(EchoShellFactory.INSTANCE); sshd.setCommandFactory(UnknownCommandFactory.INSTANCE); return sshd; }
public static SshServer setupTestServer(Class<?> anchor) { SshServer sshd = SshServer.setUpDefaultServer(); sshd.setKeyPairProvider(createTestHostKeyProvider(anchor)); sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE); sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE); sshd.setShellFactory(EchoShellFactory.INSTANCE); sshd.setCommandFactory(UnknownCommandFactory.INSTANCE); return sshd; }
public static SshServer setupTestServer(Class<?> anchor) { SshServer sshd = SshServer.setUpDefaultServer(); sshd.setKeyPairProvider(createTestHostKeyProvider(anchor)); sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE); sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE); sshd.setShellFactory(EchoShellFactory.INSTANCE); sshd.setCommandFactory(UnknownCommandFactory.INSTANCE); return sshd; }