javasftpapache-minasshdmina

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() {
   @Override
   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() {
    @Override
    public FileSystem createFileSystem(Session session) {
        // What should I do here?
        return super.createFileSystem(session);
    }
});

Solution

  • Found it.
    I had to use the VirtualFileSystemFactory class.

    This is the result:

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

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