大网数据广告活动
服务器运维问答

Restricting user group to specific folder in Win2016 server

· 52CE 我爱测

First off, I am new to this things so my technical vocabulary may not be on par with everyone. I have created a Windows 2016 server and installed OpenSSH SFTP server successfully. Unfortunately when I login to my SFTP user, I am …

问题原文

原帖链接 · user3118602 · CC BY-SA 4.0

First off, I am new to this things so my technical vocabulary may not be on par with everyone.

I have created a Windows 2016 server and installed OpenSSH SFTP server successfully. Unfortunately when I login to my SFTP user, I am able to access all the folders in C drive. I Googled and understand that this is because there is no restriction set on this user.

I have googled for several hours and came across many articles but I am getting confused by it. It seems like OpenSSH do not have an easy way to control the folder restriction to specify user and there are a few ways to do it - setting the user group policy in Windows server directly (can't seem to find an article on this), download Cygwin, use other SFTP server software, workaround with OpenSSH server config file. To be frank, I am at a loss here on which to use or follow.

My end result is to allow 1 user to have 1 access to a folder under FTP_Folder (root folder). For example, User1 can only access to Site1 folder, and User2 can only access to Site2 folder. Both Site1 and Site2 folders are stored in a root folder called FTP_Folder.

What is the best approach?

已采纳解答

原帖链接 · bjoster · CC BY-SA 4.0

You are most likely searching for the chroot equivalent ChrootDirectory in your %programdata%\ssh\sshd_config file.

This directive is only supported with sftp sessions, which sounds to me is what you are searchivn for. A remote session (SSH) into the server (cmd.exe oder powershell.exe) would not honor this.

To setup a sftp-only chroot server, set ForceCommand to internal-sftp. You may also set up scp with chroot, by implementing a custom shell that would only allow scp and sftp.

To make this simple:

  1. Make a Windows group with all your SFTP users in it
  2. Make sure, this group has access to your target directorie(s)
  3. Add subsystem sftp internal-sftp to your sshd_config (or change it)
  4. Restrict the new group to a directory through ChrootDirectory in sshd_config

Like this, for Example:

Match Group myfriendlyusergroup
    ChrootDirectory /myfriendlyusergroupshomedirectory
    AllowTCPForwarding no
    X11Forwarding no
    ForceCommand internal-sftp

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-06-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。