Score:0

How to prevent a SFTP user from seeing other directories?

cn flag

I'm setting up a Windows Server 2019-based web server. One of our vendors needs to be able to upload files. I have

  • Added sshd
  • Created a login for them to use
  • Created a group for that login
  • Added that login to the group, and removed the login from all other groups
  • Created an upload directory
  • Given the group Write and Modify permissions in that directory
  • Added the line ForceCommand internal-sftp -d "C:\inetpub\ftproot\Upload" to a Match directive for that group in sshd_config

So far, so good. That login can connect to the box via SFTP, and the session automatically begins in the directory Upload, and it can upload and download files from there. But I cannot figure out how to prevent it from seeing the contents of other directories. Just removing the login from the group Users had no effect. Denying the group Read and List in the enclosing ftproot directory results in being unable to connnect (with an authentication failure). The only suggestion I have found in an hour of Google searching is to set a value for ChrootDirectory, but that results in no login being able to connect by SFTP or SSH (with apparent failures of the service to respond). I am pretty new to Windows server, and I'm out of ideas. There must obviously be a right way to do this - can someone point me in the right direction?

[Update]

This box is running OpenSSH 7.7:

> ssh -V
OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5

When I add this line to the Match directive for the sftp group:

ChrootDirectory "C:\inetpub\ftproot\Upload"

and then attempt to connect as any user, whether or not in that group, this is what appears in sshd.log (obviously the pid, port, and timestamp will vary):

3332 2021-08-17 12:04:24.931 Failed password for invalid user sftpuser from XX.XX.XX.XX port 34240 ssh2
in flag
Assuming you are using openssh maybe https://serverfault.com/a/1006119/187998 is a solution, if not please provide more details on version and configuration. Also try to create and look at verbose logfiles.
Don R avatar
cn flag
I've added what additional information I have. I can't find any doc referring to varying the level of verbosity of the logs.
in flag
What about https://github.com/PowerShell/Win32-OpenSSH/issues/190#issuecomment-662879084 ?
Don R avatar
cn flag
@NiKiZe I just tried `LogLevel VERBOSE` but it made no difference in what was logged when I tried to connect.
Don R avatar
cn flag
Actually several posts further down there was something that seems to be the key: Do *not* use quotation marks in the `ChrootDirectory` path.
Score:1
cn flag

It seems the key piece here is not to use quotation marks around the path in this line:

ChrootDirectory C:\inetpub\ftproot\Upload

After making that change, making an SFTP connection behaved exactly as I hoped: the directory to which the group is restricted appears as the root.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.