Setting up an SFTP Server on Windows (Server) with OpenSSH (using Microsoft's port of OpenSSH)
Often times we’ll need to integrate two systems by transferring CSV files between them. The de facto file transfer protocol in this case is SFTP. When we are on Unix based systems the choice of SFTP servers is a no brainer – OpenSSH. However, until recently, on Windows we didn’t have the option of using OpenSSH (except for maybe using Cygwin). That changed when Microsoft ported OpenSSH to windows.
In this video, I want to show you how to setup an SFTP server on Windows using OpenSSH.
Microsoft’s port of OpenSSH can be found at:
https://github.com/PowerShell/Win32-OpenSSH
Text based instructions for setting up OpenSSH can be found here:
https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH
The steps in this video have been tested on Windows Server 2016. The instructions for Windows 10 will different slightly e.g. in opening up the firewall. Consult the text based instructions for more details.
NOTE: If you’re getting “Permission denied (publickey,keyboard-interactive)” errors have a look a my follow up video where I explain how you can go about troubleshooting this: https://www.youtube.com/watch?v=YBiQXkknubc
While not necessary, if you enjoyed this video, buying me a coffee is greatly appreciated!
https://www.buymeacoffee.com/prodprogrammers (no refunds)
windows server
Please do subscribe if you found this video useful.
Also, do let me know what other topics you would like covered in future videos.
Hi there 😉 I have a little question:
Situation that you have many folders and many users to see this folders.
I try with Match Group, and works…. but if you have other folder with the some user …in my case only matchs the first line.
Have any solution for this cases.
thank you
Hi I have been setting up an sftp server for the last 2 weeks and your video has really helped
That really helped a lot !!
pls any one help me how to access one user to more directory
What a great explanation, thanks a lot!
You saved me 🙂
I did this installation step by step for the one of the Global company I do provide consultancy and I just want inform other colleagues these:
If you get an "Connection Closed (WSARecv error in .sshlogs file)" error message after 16:07 sftp username@localhost step;
You can add OpenSSH folder path to the Environment Variables path section.
– run sysdm.cpl via Run
– At the Advanced tab Click Environment Variable
– Edit the Path section and add your C:Program FilesOpenSSH path as well via the Browse option, and try again, solved.
This is very useful. Thank you!
Thanks, found this very helpful.
Thanks friend, your video helped me, greetings from Brazil.
Thanks for this – very helpful. I did get a permission denied error when first trying to connect, this was due to the security permissions on the authorized_keys file. If any other user has read/write access to it you must remove them.
Well done Sir, an excellent example well executed. Thank you.
thanks , this is exactly i was looking for
GREAT. tysm!!!!!
Hi, so I am stuck at around 16:45 , when I type sftp user1@localhostinto the command window of this user I get the following:
C:Windowssystem32>sftp user1@localhost
user1@localhost's password:
Connection closed
I don't know what is causing this and I thought you might be able to help, thanks in advance.
i did all the steps. but i getting error connection closed. unable to open sftp
Thank you so much, you saved me hours of troubleshooting.
Any help on this – after I put in my password logging in to SFTP I imminently get "connection Closed". Windows 11
At 16:47 what did you put in as the fingerprint? You typed something, but I don't know what you typed? (I don't know what a fingerprint is)
when I try to connect using the sftp user@localhost command, it goes through but it doesnt change the cmd to sftp, it just stays as the current directory. I also cant connect using filezilla. Can someone help me?
Thanks, I had some issue, but with DEBUG3, I was able to solve it 🙂
Microsoft Windows does not have a built-in SFTP server. This video is very helpful, esp. if you are tech-savvy. For many small businesses, it could still be challenging as you need to make it accessible from the Internet, thus you need to properly secure your computer and you need to have a static IP address. It might be easier and better to use a cloud based SFTP server, which can be setup instantly and you don't need to be tech-savvy. Please watch this video:
https://youtu.be/iGdBX4F1e-w
really helpful..!
Thank you, a great tutorial, really helped.
i have no files on my ssh directory on 10:34
Thanks so much for the tutorial! I'm running into one problem though, I am immediately disconnected from the server when running sftp, any help would be appreciated. Note, if I comment out #ForceCommand internal-sftp in sshd_config I am able to use ssh, just not sftp.
C:Windowssystem32>sftp -v user1@localhost
OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2
debug1: Connecting to localhost [::1] port 22.
debug1: Connection established.
debug1: identity file C:\Users\user1/.ssh/id_rsa type 0
debug1: identity file C:\Users\user1/.ssh/id_rsa-cert type -1
debug1: identity file C:\Users\user1/.ssh/id_dsa type -1
debug1: identity file C:\Users\user1/.ssh/id_dsa-cert type -1
debug1: identity file C:\Users\user1/.ssh/id_ecdsa type -1
debug1: identity file C:\Users\user1/.ssh/id_ecdsa-cert type -1
debug1: identity file C:\Users\user1/.ssh/id_ed25519 type -1
debug1: identity file C:\Users\user1/.ssh/id_ed25519-cert type -1
debug1: identity file C:\Users\user1/.ssh/id_xmss type -1
debug1: identity file C:\Users\user1/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_8.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_for_Windows_8.6
debug1: match: OpenSSH_for_Windows_8.6 pat OpenSSH* compat 0x04000000
debug1: Authenticating to localhost:22 as 'user1'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:hT4UxhDQoYC25hARc6GBXsN3uVonz62ag49/SkwE3Jo
debug1: Host 'localhost' is known and matches the ECDSA host key.
debug1: Found key in C:\Users\user1/.ssh/known_hosts:1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory
debug1: Will attempt key: C:\Users\user1/.ssh/id_rsa RSA SHA256:AXOvIT/v1lYiG4VS41HeHQFdaB8Cacjau0ogD8Z6hlM
debug1: Will attempt key: C:\Users\user1/.ssh/id_dsa
debug1: Will attempt key: C:\Users\user1/.ssh/id_ecdsa
debug1: Will attempt key: C:\Users\user1/.ssh/id_ed25519
debug1: Will attempt key: C:\Users\user1/.ssh/id_xmss
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,sk-ssh-ed25519@openssh.com,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com,webauthn-sk-ecdsa-sha2-nistp256@openssh.com>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering public key: C:\Users\user1/.ssh/id_rsa RSA SHA256:AXOvIT/v1lYiG4VS41HeHQFdaB8Cacjau0ogD8Z6hlM
debug1: Server accepts key: C:\Users\user1/.ssh/id_rsa RSA SHA256:AXOvIT/v1lYiG4VS41HeHQFdaB8Cacjau0ogD8Z6hlM
debug1: Authentication succeeded (publickey).
Authenticated to localhost ([::1]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: Sending subsystem: sftp
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Connection closed
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3144, received 2924 bytes, in 0.1 seconds
Bytes per second: sent 23371.3, received 21735.9
debug1: Exit status 1
C:Windowssystem32>
Really useful video! Thank you for sharing knowledge.
Thank you so much.it helped me a lot to set up SFTP. Please create some more descriptive videos on its different possible configurations in the config file.
great tutorial. thank you.
Hi, Thank you very much for this video. It is very helpful really appreciate. I did everything as per the guidance, but I am having an error of 'connection closed' while connecting to the sftp server from another client. I tried disabling firewall, adding a port 22 rule and folder permission. Do you have any idea about how to fix it or what goes wrong?
Thank you so much for awesome video , great explanation, this is exactly what I was looking for.
Hello, thanks! It was perfect