Copy Files Between Windows and Linux Using Command Line

Copy files from windows to linux

It is not always that you will need to copy a file from Windows to Linux or vice versa. But at times when you are automating things or trying to achieve some copy functionality using a script, it is good to have a utility to do that. Here is where pscp comes into play. Using pscp you can copy the file to/from windows and Linux. In this guide, I will go through the steps of doing the same.

Copy File from Windows To Linux

1. Download pscp.exe from here

2. copy the pscp.exe executable to the system32 directory of your windows machine. This folder normally exists in C:\Windows\System32 path.

3. Open PowerShell and use the following command to verify if pscp is accessible from the path.

pscp

4. Use the following format to copy the file to the Linux box.

pscp -pw password C:\Users\Admin\Desktop\test.txt  \
[email protected]:/home/vagrant
  1. -pw for the password.
  2. replace password with the Linux user password.
  3. C:\Users\Admin\Desktop\test.txt represents the path of the file that has to be copied to the Linux system.
  4. 192.168.33.10 is the IP of the Linux server.
  5. /home/vagrant is the user-accessible path in the Linux system to copy the file.

If you are using private keys for authentications, you can use -i flag instead of -pw followed by the path to the .ppk file. If your key file is in pem format, you can use the puttygen command to convert it to ppk.

Info: Learn Linux & Windows administration from Pluralsight with its 10 days free account

For key-based authentication, the command looks like below.

pscp -i /path/to/key.ppk C:\Users\Admin\Desktop\test.txt \
[email protected]:/home/vagrant

Copy File From Linux To Windows

You can use pscp to copy files from Linux to windows. use the following command format for the same.

pscp -pw password [email protected]:/path/to/file \
C:\Users\Admin\Desktop\

The above command will copy the file in Linux from the specified path to the Windows desktop.

1 Shares:
2 comments
Leave a Reply

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

You May Also Like