Installing, testing and uninstalling an OpenSSH-based SFTP server in Windows

Step by Step guide 

Installing and setting up an SFTP server (SSH FTP)

First you need to download and install OpenSSH from GitHub:
https://github.com/PowerShell/...
Download the archive: OpenSSH-Win64.zip

1) Extract the contents of the archive to a target directory, for example: "C:\Windows"

2) Open system properties (WIN+R, command "sysdm.cpl") -> Advanced -> Environment variables
The window that appears has two sections: the top one contains user environment variables, the bottom one contains system variables.
In the system variables select "Path" variable, click on "Change...".

3) In the window that opens, click on "New" and enter the OpenSSH directory path from step 1, in this example: "C:\Windows\OpenSSH-Win64"

4) Launch "PowerShell" as Administrator:
Start, type "PowerShell"→ Right click on "PowerShell" → Run as Administrator

5) Navigate to the OpenSSH directory, in this example: "C:\Windows\OpenSSH-Win64"

cd C:\Windows\OpenSSH-Win64

Install the OpenSSH server:
(a green "sshd and ssh-agent services successfully installed" message should appear);

.\Install-sshd.ps1

Enable autorun for SSHD service:

Set-Service -Name sshd -StartupType ‘Automatic’

Open TCP port 22 in the Windows firewall for incoming traffic to the SSH server:

New-NetFirewallRule -Protocol TCP -LocalPort 22 -Direction Inbound -Action Allow -DisplayName SSH

Set up the file owner and access rights: (Answer each question with a "Y")

.\FixHostFilePermissions.ps1


6) Open service list (WIN+R, command "services.msc") -> Double click on "OpenSSH SSH Server" → Set startup type: "Automatic", click on "Run" → OK

Checking SFTP connection using WinSCP

Download and run the free WinSCP client.
In the connection settings window, select the SFTP file transfer protocol, specify the server name and the details of the Windows account under which you are connecting

If everything is set up correctly, the client should connect to the SFTP server and display a list of files in the user's home directory (the default directory with the user's profile).
Using the familiar file manager interface, files can be securely copied between the server and the client. File transfer will be performed via secure SFTP protocol.

Uninstalling the Win32 OpenSSH service

To correctly remove the Win32 OpenSSH service from the system:

1) Launch "PowerShell" as Administrator:
Start, type "PowerShell"→ Right click on "PowerShell" → Run as Administrator

2) Navigate to the OpenSSH directory, in this example: "C:\Windows\OpenSSH-Win64"

cd C:\Windows\OpenSSH-Win64

3) Stop the SSHD service:

Stop-Service sshd

4) Uninstall the OpenSSD service:

.\uninstall-sshd.ps1