DEV Community

Nate
Nate

Posted on Originally published at shadeterm.com

Host an SFTP Server on Windows with OpenSSH

SFTP on Windows is provided by the OpenSSH Server feature. Installing OpenSSH Client lets your machine connect to other servers; it does not make your machine an SFTP host.

The setup is straightforward: install the server capability, start sshd, check the firewall, and verify an actual file transfer. SFTP uses SSH, normally over TCP port 22, so there is no separate SFTP service or port to configure.

Install and start OpenSSH Server

Run PowerShell as an administrator on the Windows machine that will receive files. First check whether the server capability is already installed:

Get-WindowsCapability -Online |
  Where-Object Name -like 'OpenSSH*' |
  Select-Object Name, State
Enter fullscreen mode Exit fullscreen mode

If OpenSSH.Server is NotPresent, install it:

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Enter fullscreen mode Exit fullscreen mode

Then start the SSH service and configure it to start with Windows:

Start-Service sshd
Set-Service -Name sshd -StartupType Automatic
Get-Service sshd
Enter fullscreen mode Exit fullscreen mode

Get-Service should show Running. Windows Server 2025 includes OpenSSH by default, but the service still needs to be enabled. On other versions, OpenSSH Server may be installed as an optional feature.

Check the listener and firewall

A running service and an open firewall rule are separate requirements. Check whether anything is listening on the default SSH port:

Get-NetTCPConnection -LocalPort 22 -State Listen -ErrorAction SilentlyContinue
Enter fullscreen mode Exit fullscreen mode

OpenSSH installation normally creates an inbound firewall rule. Inspect it before making changes:

Get-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -ErrorAction SilentlyContinue |
  Format-List Name, Enabled, Direction, Action, Profile
Enter fullscreen mode Exit fullscreen mode

If the rule is missing, an administrator can create one for TCP port 22:

New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' `
  -DisplayName 'OpenSSH Server (sshd)' -Enabled True `
  -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
Enter fullscreen mode Exit fullscreen mode

For anything beyond a trusted lab, limit access to appropriate client addresses or networks instead of exposing the service broadly. A remote client also needs a route to the server; a private home-network address is not reachable from the public internet without a VPN or another deliberately configured network path.

Verify the SFTP subsystem

The server configuration is usually at C:\ProgramData\ssh\sshd_config. Check that it contains an active SFTP subsystem directive, and that the server binary exists:

$config = Join-Path $env:ProgramData 'ssh\sshd_config'
Select-String -Path $config -Pattern '^\s*Subsystem\s+sftp'
Test-Path "$env:WINDIR\System32\OpenSSH\sftp-server.exe"
Enter fullscreen mode Exit fullscreen mode

Windows OpenSSH commonly uses Subsystem sftp sftp-server.exe; internal-sftp is another option. Keep the existing working directive—do not add a second Subsystem sftp line.

If you edit the configuration, validate its syntax before restarting the service:

& "$env:WINDIR\System32\OpenSSH\sshd.exe" -t
Enter fullscreen mode Exit fullscreen mode

A successful syntax check does not confirm that a user can log in or write to a directory. Keep a recovery route available before restarting a remote server after configuration changes.

Test a real upload and download

Start with a local test on the Windows server. This checks the service, account, SFTP subsystem, and file access without depending on another machine’s network path:

Set-Location $HOME
'Windows SFTP test' | Set-Content -Encoding ascii 'sftp-test.txt'
sftp "$($env:USERNAME)@localhost"
Enter fullscreen mode Exit fullscreen mode

At the sftp> prompt, try uploading and downloading the file:

pwd
put sftp-test.txt
ls -l sftp-test.txt
get sftp-test.txt sftp-test-downloaded.txt
exit
Enter fullscreen mode Exit fullscreen mode

Then test from an authorized second machine, using the server’s reachable address and an account permitted to log in:

sftp USER@SERVER_IP
Enter fullscreen mode Exit fullscreen mode

A successful TCP check alone is not enough: it does not test authentication, the SFTP subsystem, or write permissions. Similarly, a successful login does not prove that uploads work. Verify both put and get with a test file.

If SSH uses a custom port, specify it with uppercase -P in the SFTP client, for example sftp -P 2222 USER@SERVER_IP.

Keep accounts and file access scoped

Use a normal, least-privilege Windows account where possible, and give it access only to the directories it needs. Public-key authentication is supported, but Windows OpenSSH key locations depend on the account and effective server configuration. Administrator-group accounts may use a shared administrators_authorized_keys file rather than a key file in the user profile. NTFS permissions on authorized keys matter; do not make private keys broadly readable or loosen key checks to troubleshoot a login.

An SFTP-only account is a more advanced setup. Windows OpenSSH supports ChrootDirectory for SFTP sessions, not as a restriction on an ordinary Windows shell. A configuration may use ForceCommand internal-sftp, but the chroot’s NTFS ACLs must also be correct: the user must not be able to write to the chroot root, and should receive write access only to an intended subdirectory. Test both file-transfer access and denial of shell access before relying on this restriction.

For a Linux host, the filesystem ownership and permission model is different; see this Ubuntu and Debian SFTP server setup rather than applying Linux chmod instructions to NTFS.

Troubleshoot by symptom

  • Connection refused: Check Get-Service sshd, the port listener, and the inbound firewall rule.
  • Connection times out: Check routing, network firewalls, and whether the rule allows the client’s source address.
  • Permission denied: Confirm the username, authentication method, authorized key location, and relevant NTFS permissions.
  • Subsystem request failed: Inspect the active Subsystem sftp line and OpenSSH logs.
  • Login works but upload fails: Check write access to the destination directory and, if configured, chroot permissions.

To discover available OpenSSH event logs on the server, run:

Get-WinEvent -ListLog '*OpenSSH*' -ErrorAction SilentlyContinue
Enter fullscreen mode Exit fullscreen mode

If OpenSSH/Operational is available, inspect recent events with:

Get-WinEvent -LogName 'OpenSSH/Operational' -MaxEvents 30 -ErrorAction SilentlyContinue |
  Select-Object TimeCreated, Id, LevelDisplayName, Message
Enter fullscreen mode Exit fullscreen mode

Once the command-line transfer works, a graphical client can use the same host, port, account, and authentication method. This comparison of SFTP clients can help you choose one for your workflow. Remember that a GUI client does not bypass the server’s account or NTFS permissions.

I originally published a more detailed version of this guide on the ShadeTerm blog.

I'm also building ShadeTerm — an SSH client where every server gets its own workspace for terminals, SFTP, code, and databases.

Top comments (0)