I got a problem, that I cannot solve myself. I tried to google it, but no satiscactory solution that i could find.
I have a server that is available with let's say 3 different IP addresses (A,B,C), and a user login lets say "user".
I need to setup an sftp server that: when connected with IP A, the SFTP server will announce itself with Key A, when connected with B, announces itself with key B, and so on.
But that is not the end, of the problem, I want to set it up, so when a client tries to connect to "user" with IP A, it would use directory A for accessing user files, when connected with IP B it would use direcotry B, and when connected with IP C, then it would use directory C. I thought of proftpd with sftp mod on, but I got stuck on how to configure directories, that would be accessed with login "user". for eg.
if client tries to access file: user@A:file.dat
real pathname would be directoryA/file.dat
if client tries to access: user@B:file.dat
the real pathname would be directoryB/file.dat
and so on... Now the question is, how to set it up?

  • multiple instances of sshd bound to the three ips would probably do this. If you are using keys to connect, I notice you can specify environment variables within authorized_keys, and may be able to affect the home directory of the connecting user. – GeoSword May 18 '16 at 12:10
  • yes, that I considered,but I will have more than 3 ips, and unfortunately I will have to configure more and more with time. Running multiple instances of ssh would be kind of problematic... And yes, I will have a key authorization... – Zdzislaw Mogilny May 18 '16 at 12:12
  • Do they have to use the same private key with all ip addresses? user@A, user@B, user@C it should be the same private key? – ALex_hha May 30 '16 at 15:24

Your proftpd.conf for this would, I think, look something like this:

<IfModule mod_sftp.c>
  # Virtual host configuration for server A
  <VirtualHost a.a.a.a>
    Port 22
    SFTPEngine on
    SFTPHostKey /path/to/key/A

    # Restrict members of group A to this directory
    DefaultRoot /path/to/directoryA groupA

  # Virtual host configuration for server B
  <VirtualHost b.b.b.b>
    Port 22
    SFTPEngine on
    SFTPHostKey /path/to/key/B

    # Restrict members of group A to this directory
    DefaultRoot /path/to/directoryB groupB

  # Virtual host configuration for server C
  <VirtualHost c.c.c.c>
    Port 22
    SFTPEngine on
    SFTPHostKey /path/to/key/C

    # Restrict members of group C to this directory
    DefaultRoot /path/to/directoryC groupC

The key part of making the above work is to use the optional group parameter of the DefaultRoot directive (for more info, I recommend the Chroot howto).

The user name "user" would be configured slightly different for each of your virtual hosts. For server A, "user" would be a member of group A. For server B, "user" would be a member of group B. And for server C, "user" is a member of group C. If you did not want to use chroot restrictions for any reason, you could use the DefaultChdir directive instead; this simply places the authenticated client at the requested directory at the start of their session, once they've authenticated.

Hope this helps!

| improve this answer | |

You could try Sysax Server. It is not free but gets the job done.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.