Windows-based SFTP Server
This guide demonstrates the precedure for creating a Windows-based SFTP server using the built-in OpenSSH instance. The end result is an SFTP server only available to the “sftpusers” group via sftp only. There will be no ssh shell access to the server.
System Requirements
- Windows 10 1809 or later, Windows Server 2019 or later
- A careful eye on security
- Recommendations, in case of compromise
- Do not add the server to the domain
- If the server is exposed to the internet, keep it in a DMZ
- Do not use the server for other purposes
Create SFTP Users
- Add local user account for service (eg. ‘Powerschool’)
- Add local group named ‘sftpusers’
- Add service user to ‘sftpusers’ group
Create SFTP Chroot folder
- Under C:\, create a folder named ‘sftp’
- Edit the folder security settings and disable inheritance
- Add ‘sftpusers’ group with Modify rights
Install OpenSSH Server
- Open PowerShell as administrator
- Enter the following command
1
Get-WindowsCapability -Online -Name OpenSSH.Server* | Add-WindowsCapability -Online
Start OpenSSH Service
- Open PowerShell as administrator
- Enter the following commands
1 2
Set-Service sshd -StartupType Automatic Start-Service sshd
Configure OpenSSH Service
- Open PowerShell as administrator
- Backup default config
1 2
cd C:\ProgramData\ssh cp .\sshd_config .\sshd_config.bak
- Open configuration file with
1
notepad.exe sshd_config
- Replace entire configuration with
1 2 3 4 5 6 7 8
ForceCommand internal-sftp Subsystem sftp internal-sftp -d "C:\sftp\" ChrootDirectory C:\sftp PermitTunnel no AllowAgentForwarding no AllowTcpForwarding no X11Forwarding no AllowGroups sftpusers
- Save and close the file
Restart OpenSSH Service
- Open PowerShell as administrator
- Enter the following command:
1
Restart-Service sshd
Test SSH Connection (should fail)
- Verify you are not able to connect to the server from another machine via ssh with any user account
1
ssh <useraccount>@<newserverip>
Test SFTP Connection (should work)
- Use sftp to connect to the server (you can also use WinSCP of Filezilla)
1
sftp <useraccount>@<newserverip>
- Once connected, verify you cannot change to a higher directory
cd ..
, for example, should return “permission denied”
Ensure a Safe Environment
- Edit the local firewall to only allow certain hosts/networks to port 22
- If allowing access from the internet, edit the internet firewall ACLs to only allow traffic in from trusted IP addresses on port 22
- Ensure automatic updates are running and do not require intervention.
- Ensure endpoint security is installed and running
This post is licensed under CC BY 4.0 by the author.