如何在 Windows Server 上的 OpenSSH 中限制用户使用 sftp?

Tom*_*bík 8 windows ssh powershell openssh sftp

我正在使用从https://github.com/PowerShell/Win32-OpenSSH/releases下载的 OpenSSH 。

我的目标是设置一个 ssh 服务器,允许 sftp 文件传输而无需 ssh 访问。根据OpenSSH提供的官方文档,Windows从7.7版本开始应该支持这一点。已发布,应该在 sshd_config 中设置限制,我尝试使用该文件一段时间,但我无法限制自己只能访问子文件夹,这就是我的配置文件中的内容添加:

Subsystem   sftp    sftp-server.exe
ForceCommand internal-sftp 
ChrootDirectory c:\users\myusername 
AllowTcpForwarding no 
PermitTunnel no
GatewayPorts no
Run Code Online (Sandbox Code Playgroud)

谁能告诉我为什么这不起作用?或者我不能像这样设置 SFTP 访问?

另一种选择是禁用 SSH 连接。如何在 Windows 中使用 OpenSSH 实现这一目标?

Cpt*_*ale 7

来自PowerShell-OpenSSH GitHub上的 Mika-n :

这适用于 OpenSSH-Win64 8.1.x 版本,但您需要设置以下 sshd_config 选项(默认情况下位于%PROGRAMDATA%\SSH\Windows 平台的文件夹位置):

ForceCommand internal-sftp 
Subsystem  sftp   sftp-server.exe -d "D:\MyDataRoot\" 
ChrootDirectory D:\MyDataRoot

PermitTunnel no 
AllowAgentForwarding no 
AllowTcpForwarding no
X11Forwarding no 
AllowUsers sftpuser
Run Code Online (Sandbox Code Playgroud)

因此,请考虑添加子系统行-d来设置文件夹,或添加-d到您的ForceCommand条目中。

请注意,您还应该确保用户拥有正确的文件系统权限,以便将它们也包含在文件夹中。