Copy files from Windows to Linux using PowerShell Remoting

Not so long ago, I had to copy some files from Windows environment to Linux VM. I am sure, there are million options how to do it, specially using SCP or SMB protocols, but I was wondering (at the time), if I could achieve the same using PowerShell.

Today I KNOW, that it CAN be done, and I will show you how.

Pre-requirements…
  1. Install PowerShell version 6 to local Windows 10 client machine following instructions at https://github.com/PowerShell/PowerShell
  2. Install PowerShell version 6 to remote Linux following same instructions as  mentioned above (for CentOS I used https://github.com/PowerShell/PowerShell/blob/master/docs/installation/linux.md#centos-7)
  3. Install SSH Client as optional feature to local Windows 10, using instructions from Thomas Maurer https://www.thomasmaurer.ch/2017/11/install-ssh-on-windows-10-as-optional-feature/
  4. Configure SSH to accept and trust PowerShell instructions from here https://blogs.technet.microsoft.com/heyscriptingguy/2017/12/29/cross-platform-powershell-remoting-in-action/
    You don’t need go through all mentioned here (if you don’t want), but be extra careful to configure:
    –> sshd_config in C:\Windows\System32\OpenSSH on Windows

 

* You might need to change permissions on file to be able to write change

–> sshd_config in /etc/ssh/ on Linux

* Here you will need to restart sshd service

Transferring files…

Now when we have groundwork done for PowerShell Remoting, we can misuse it also for transferring files into remote session, using 2 short steps.

Connect to remote Linux machine with PSSession:

Make the actual copy:

 

And it is done!

 

…until next time…

Stay curious and never stop learning…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.