Changing the Default Directory for OpenSSH SFTP on Windows Server 2022

Abstract: Restrict OpenSSH SFTP users to a specific directory on Windows Server 2022 by configuring ChrootDirectory in sshd_config.

Created: 2026-09-22 by
To change the default directory for OpenSSH SFTP on Windows Server 2022, you must modify the SSH server configuration file located at C:\ProgramData\ssh\sshd_config. By adding a Match block that targets the specific user and setting the ChrootDirectory directive, you can enforce a strict chroot environment. This ensures that all SFTP sessions for that user are rooted in a designated folder, enhancing security by preventing access to the rest of the file system.

Understanding the Chroot Directory Mechanism

The OpenSSH server on Windows utilizes a feature called "chroot" to restrict a user's file system access. When configured correctly, the user cannot navigate above their assigned root directory using commands like cd ... This is critical for secure file transfer servers where users should only interact with their own data. The configuration relies on the sshd_config file, which controls how the SSH daemon behaves. Unlike Linux, where this might be handled by PAM modules or home directory defaults, Windows requires explicit directives in the main configuration file. It is important to note that the path specified in the configuration must be accessible by the system account and properly secured to prevent privilege escalation. For more information on securing your connection, see our guide on Connect to OpenSSH Server on Windows using PowerShell.

Preparing the Target Directory

Before editing the configuration file, you need to create the directory that will serve as the new default location. This directory must be owned by the SYSTEM account and must not be writable by any other user or group. If the permissions are too open, the SSH server will refuse to start or will fail to chroot the user, logging an error about insecure directories. Create a new folder, for example, C:\SFTP\Users\JohnDoe. Then, right-click the folder, select Properties, and go to the Security tab. Remove all users except SYSTEM. Ensure that SYSTEM has Full Control. If you are managing multiple users, you can create a parent directory structure like C:\SFTP and then subdirectories for each user, ensuring each subdirectory has the correct ownership. This step is crucial because the ChrootDirectory directive requires that the target directory and all its parent directories up to the root are owned by SYSTEM and not writable by others.

Editing the sshd_config File

The core of the solution lies in modifying the sshd_config file. On Windows Server 2022, this file is typically located at C:\ProgramData\ssh\sshd_config. You must use a text editor with administrative privileges, such as Notepad running as Administrator, to make changes. Opening the file without elevation will result in a permission denied error when saving. Locate the section near the bottom of the file where match blocks are defined. Add a new block specifically for the user whose default directory you wish to change. The syntax is straightforward but case-sensitive. Use the following structure:
Match User JohnDoe
    ChrootDirectory C:\SFTP\Users\JohnDoe
    ForceCommand internal-sftp
The Match User directive ensures these settings apply only to the specified user. The ChrootDirectory sets the root of the file system for that session. The ForceCommand internal-sftp is essential; it prevents the user from executing shell commands via SSH, restricting them strictly to SFTP operations. Without this, the user might still get a command prompt if they have shell access enabled elsewhere. After adding this block, save the file. Always back up the original sshd_config before making changes to allow for easy rollback if something goes wrong.

Restarting the SSH Service

Changes to the configuration file do not take effect immediately. You must restart the OpenSSH service for the new settings to load. Open PowerShell as Administrator and run the following command:
Restart-Service sshd
If the service fails to restart, check the event viewer under Applications and Services Logs > OpenSSH > Operational. Common errors include syntax mistakes in the config file or incorrect directory permissions. If the service starts successfully, test the connection from a client machine. Attempt to log in via SFTP and try navigating to the parent directory. The user should be unable to go above their chrooted directory. For additional context on managing connections, you may find it useful to review Windows Server 2019: SSH Server Max Number of Connections or Concurrent Users, as limiting concurrent sessions can also impact resource usage in a chrooted environment.

Troubleshooting Common Issues

Even after correct configuration, issues may arise. The most frequent problem is the "Insecure directory" error. This occurs if the chroot directory or any of its ancestors are writable by non-SYSTEM users. Double-check the NTFS permissions. Another issue is the user being locked out entirely. This can happen if the ForceCommand internal-sftp conflicts with existing public key authentication settings or if the user does not have read/write permissions within the chrooted directory itself. Remember that inside the chroot, the root is the specified directory, so the user needs write access to folders within C:\SFTP\Users\JohnDoe, not the directory itself relative to the OS root.

Frequently Asked Questions

Can I use the same chroot directory for multiple users?

No, each user should have their own unique chroot directory to ensure isolation. Sharing a directory between users can lead to permission conflicts and security vulnerabilities where one user might access another's files.

What happens if I forget to set ForceCommand internal-sftp?

Without forcing the internal SFTP command, authenticated users may gain access to a standard shell if their account has login rights. This bypasses the chroot restriction and allows them to execute arbitrary commands, defeating the purpose of the secure setup.

How do I verify the current sshd_config syntax?

You can test the configuration by running sshd -t in an elevated PowerShell window. This command checks for syntax errors and reports any issues before you restart the service, preventing downtime due to misconfigurations.

Does changing the default directory affect FTP clients?

This configuration only applies to SFTP connections managed by the OpenSSH server. Traditional FTP clients using different protocols or services are unaffected unless they also connect through the same OpenSSH instance and adhere to the same match rules.

Is it necessary to disable password authentication for this setup?

While not strictly required for the chroot to work, disabling password authentication and using keys is recommended for enhanced security. This reduces the risk of brute-force attacks against accounts that are already restricted to a specific directory.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More