Alon Amir Alon Amir - 8 months ago 72
Java Question

Apache Mina SSHD 1.0.0 set user directory & mapping

Trying to set a home directory for a user using Apache Mina SSHD embedded in Java.

Both solutions are deprecated in 1.0 in-

How to Set Root Directory in Apache Mina Sshd Server in Java

How to override getVirtualUserDir() in Apache Mina sshd-core version 0.14.0

In 0.14.0 the following worked fine:

sshd.setFileSystemFactory(new NativeFileSystemFactory() {
public FileSystemView createFileSystem(final Session session) {
HashMap<String,String> map = new HashMap<String,String>();
map.put("/", "/Users/someone/Documents");
return new NativeFileSystemView(session.getUsername(), map, "/");

This is as far as I got:

sshd.setFileSystemFactory(new NativeFileSystemFactory() {
public FileSystem createFileSystem(Session session) {
// What should I do here?
return super.createFileSystem(session);


Found it.
I had to use the VirtualFileSystemFactory class.

This is the result:

VirtualFileSystemFactory fsFactory = new VirtualFileSystemFactory();
fsFactory.setUserHomeDir(userName, realDirectory);

Note: If you're using OS X or linux, don't forget to chmod your path first.