If you have two machines running Windows and Linux and want to copy files from one to another, this step-by-step guide will help you get the job done. You can use PowerShell Remoting Over SSH to copy files from Windows to Linux. The main requirement is that you must have PowerShell 6 or later versions.
PowerShell is one of the best and most useful command-line utilities, allowing you to execute countless commands to fulfill all kinds of demands. One of the handiest features of PowerShell is that you can connect Windows and Linux computers via a remote session and use it as a cross-platform application. The same thing can be used to copy files from Windows and paste them on the Linux machine. Whether it is audio, video, document, or anything else, you can make a copy of that via this guide.
Before getting started with this process, you must do a few things:
- Check PowerShell version. If it is lower than PowerShell 6, you need to update it. In that case, you need to go to learn.microsoft.com and use any of the methods to update it to the latest version. For your information, downloading the MSI package is the easiest way you can use.
- You must have PowerShell on the target Linux computer. If you do not have it already, you can visit learn.microsoft.com to download and install PowerShell on Linux.
- A remote session must be established already. For that, you need SSH Remoting. If you use Ubuntu, you can get started with these commands: sudo apt install openssh-client and sudo apt install openssh-server. It asks for a password as well.
Once you are at this stage, you are all set to go.
How to Copy files from Windows to Linux using PowerShell
To copy files from Windows to Linux using PowerShell, follow these steps:
- Create a new PowerShell remote session.
- Select the file you want to copy.
- Right-click on it and select the Copy as path option.
- Use the Copy-Item cmdlet to start copying.
To learn more about these steps, continue reading.
As said earlier, you need to create a remote PowerShell session first. For that, Microsoft suggests that you use this command:
$s = New-PSSession -HostName host-ip -UserName username
Don’t forget to replace the host-ip and username with the original host IP and username. This username denotes the host computer’s username.
Following that, you need to choose the file you want to copy. Right-click on the file, and select the Copy as path option.
Although there is another method to select the file and obtain the file path, this method has been proven easier, as per our testing. However, if you want to use that method, you need to use this command first:
Enter-PSSession $s
Then, use the dir command to open and view the directory.
Next, you need to enter this command containing the Copy-Item cmdlet:
Copy-Item .\file-path /home/username -ToSession $s
Again, don’t forget to replace the file-path with the original file path and username with the original username.
Once done, the file will be copied immediately.
I hope it helped.
Read: How to install Windows Subsystem for Linux 2 on Windows
How do I copy files from Windows to Linux?
Although there are multiple ways to copy files from Windows to Linux, you can use PowerShell to get the job done. For that, you need to create a PowerShell Remoting Over SSH first. Then, you can use the Copy-Item cmdlet to start copying the file from one to another.
How to copy from Windows path to Linux?
To copy files from Windows to Linux using the command line, you can use PowerShell. First, check if your PowerShell is updated or not. Then, create a remote session over SSH via PowerShell. Finally, choose the file on your Windows computer and use the aforementioned command to get it done.