Win32-OpenSSH icon indicating copy to clipboard operation
Win32-OpenSSH copied to clipboard

OpenSSH CHROOT for Windows 12 - Restrict SFTP to specific folder does not work

Open karn2020 opened this issue 4 years ago • 3 comments

I have portable OpenSSH setup and services for sshd and agent are configured from the OpenSSH folder (C:\OpenSSH-Win64). Also we have changed the default port and it is working fine.

I have referred the earlier post https://github.com/PowerShell/Win32-OpenSSH/issues/190 about setting CHROOT, but user is redirecting to it's home directory i.e. "/C:/Users/testuser" (username = "testuser") instead of mentioned ChrootDirectory.

Below are configuration of my sshd_config_default file

ForceCommand internal-sftp
Match User testuser
Subsystem  sftp   sftp-server.exe -d "/E:/SHARED_LOCATION/ABC"
ChrootDirectory /E:/SHARED_LOCATION/ABC

PermitTunnel no
AllowAgentForwarding no
AllowTcpForwarding no
X11Forwarding no
AllowUsers testuser 

Please let me know if I am missing anything.

Permissions for E:\SHARED_LOCATION are Read & Execute

Also is it possible to have 2 different users or groups have different ChrootDirectory settings in ssh_config_default ?

karn2020 avatar Oct 14 '20 15:10 karn2020

Why does your sshd_config file look so "weird"?

  • The order of commands are totally different from default...
  • you use both ForceCommand internal-sftp and Subsystem sftp sftp-server.exe, which is most likely wrong.
  • You put the Match User testuser in between when it should be somewhere last in that file.
  • You say you use sshd_config_default which is not a recognized filename AFAIK.

eabase avatar Oct 14 '20 16:10 eabase

Even after changing settings as below , it is not redirecting to proper folder (E:\SHARED_LOCATION\ABC)

AllowAgentForwarding no
PermitTunnel no
#AllowTcpForwarding no
#X11Forwarding no
#AllowUsers testuser

ForceCommand internal-sftp
#Match User testuser
ChrootDirectory /E:/SHARED_LOCATION/ABC
AllowTcpForwarding no
PermitTTY no
X11Forwarding no
Match User testuser

karn2020 avatar Oct 15 '20 08:10 karn2020

I have the same issue as @karn2020 mentionned here

ChamkhiAnas avatar Sep 16 '22 12:09 ChamkhiAnas