In this updated guide, I will walk you through the steps to copy files from Windows to Linux using easy-to-follow steps.
I will show you two ways to copy files from windows to Linux
- Using command line with pscp
- Using GUI FTP utility.
Copy File from Windows To Linux Using PSCP
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.
Step 1: Download pscp.exe from here. Select the appropriate package.
Step 2: copy the pscp.exe executable to the system32 directory of your windows machine. This folder normally exists in C:WindowsSystem32
path.
Step 3: Open Windows PowerShell and use the following command to verify if pscp is accessible from the path.
pscp
You should see the following output.
Step 4: Use the following format to copy the single file from Windows to the Linux box.
pscp -pw password C:UsersAdminDesktoptest.txt [email protected]:/home/vagrant
Here is the explanation of the command.
-pw
for the password.- Replace
password
with the Linux user password. C:UsersAdminDesktoptest.txt
represents the path of the file that has to be copied to the Linux system.192.168.33.10
is the IP of the Linux server./home/vagrant
is the user-accessible path in the Linux system to copy the file.
If you want to copy all the files in a directory to Linux, you need to add a start to the folder. eg. folder*
. An example is shown below.
pscp -pw password C:UsersAdminDesktopfolder*
[email protected]:/home/vagrant
If you are using Linux private keys for authentication, you can use -i
flag instead of -pw
followed by the path to the .ppk
, .pem
or id_rsa
file.
If your key file is in pem
format, you can use the puttygen command to convert it to ppk. See this ec2 server guide for the pem
to ppk
conversion.
Info: Learn Linux & Windows administration from Pluralsight with its 10 days free account
For Linux Private key-based authentication, the command looks like below.
pscp -i /path/to/key.ppk C:UsersAdminDesktoptest.txt [email protected]:/home/vagrant
Copy File From Linux To Windows Using PSCP
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:UsersAdminDesktop
The above command will copy the file in Linux from the specified path to the Windows desktop.
Copy File from Windows To Linux Using FTP GUI
If you are not familiar with the Windows command line, you can use an FTP tool like Filezilla.
This tool is really helpful if you are working with Web Hosting providers to upload your website files from your local workstation.
You can download Filezilla from here –> FileZilla Download.
After download, install Filzill as you install any other windows software.
After installation, open the Filezilla app and enter the remote Linux server details as shown below. It will connect to the server and shows the remote server files in the file explorer.
To upload a file, all you have to do is do a right-click and click upload, as shown in the image below. The file will get uploaded to the remote path, which is opened in the Filezilla explorer. You can also change the remote path from Filezilla.
Conclusion
I have shown two best and recommended ways to transfer files from Windows to Linux and vice versa.
If you face any issues while copying files, please drop the issues as a comment. I will look into it.
He loves to write about WordPress and cloud hosting. He is a Cloud Architect by profession with experience hosting high scale applications on Amazon and Google cloud platforms. He has successfully set up and grown several WordPress websites by following good tech practices.
Copying data from a Windows PC to Linux—or in the other direction—can seem intimidating at first. After all, it’s something that seems like it should be simple but turns out to be difficult.
In truth, sharing files from Windows to Linux is easy, but only if you know how to do it. Ready to find out? Here’s everything you need to know about how to transfer files from Windows to Linux and back again.
4 Ways to Transfer Files From Windows to Linux
If you want to move data between Windows and Linux operating systems, it’s easier than you think. We’ve compiled four ways for you to do this:
- Securely copy files via SSH
- Windows to Linux file transfer with FTP
- Share data using sync software
- Use shared folders in your Linux virtual machine
With each of these methods, you’ll be able to easily (and, in some cases, effortlessly) carry out Linux to Windows or Windows to Linux file transfer.
Let’s look at them in turn and find out which one suits you best.
1. Copy Files Between Windows and Linux via SSH
With SSH enabled on your Linux device, you can send data via the command line from one computer to another. For this to work, however, you will need to set up an SSH server on your Linux machine.
Start by opening a terminal and updating and upgrading the OS.
sudo apt update
sudo apt upgrade
Once complete, install the SSH server. The OpenSSH server is a good option.
sudo apt install openssh-server
Wait while it installs. To check at any time if the OpenSSH server is running, use:
sudo service ssh status
To transfer data from Windows, use an SSH client like PuTTY. This needs the PSCP (secure copy client) tool to download to your Windows system to run alongside PuTTY. Find both on the PuTTY downloads page.
Download: PuTTY
Note that while PuTTY will need installing, PSCP won’t. Instead, save the downloaded pscp.exe file in the root of the Windows C: drive or else set it up as an environment variable. You’ll also need to confirm the IP address of the Linux device. Check in the Linux terminal with:
hostname -I
With a connection established, you can transfer a file from Windows to Linux like this:
c:pscp c:somepathtoafile.txt user@remoteIP:homeusersomepathnewname.txt
You’ll be prompted for your password for the Linux computer before the transfer commences.
Want to copy files from Linux to Windows in the same SSH session? This command will download the specified file to the current directory:
c:pscp user@remoteIP:homeusersomefile.txt .
Note the lone period at the end, which you must include, or the transfer will not work.
2. How to Transfer Files From Linux to Windows Using FTP
You can also use a file transfer protocol (FTP) application with SSH support. Transferring files via SFTP in a mouse-driven user interface is arguably easier than relying on typed commands.
Again, an SSH server must be running on the Linux machine before you start. You should also ensure you have installed an FTP app on Windows, like FileZilla, which has SFTP support.
Download: FileZilla
To use this method, run FileZilla, then:
- Open File > Site Manager
- Create a New Site
- Set the Protocol to SFTP
- Add the target IP address in Host
- Specify a username and password
- Set the Logon Type to Normal
- Click Connect when ready
You can then use the FTP app to move files from Windows to Linux and back using drag and drop.
Another option you should consider is a file-syncing program. These are typically cross-platform and use an encrypted key to manage the connection between devices.
All you need to do is install the app, nominate a sync folder, then create the key. Set this up on the second PC, and your data will then sync. Two good options are available for this:
- Resilio Sync: Formerly known as BitTorrent Sync, Resilio is available on almost any platform you can think of. There is a paid version, but the free option is enough for syncing two devices
- Syncthing: For Linux, Windows, macOS, and Android, this Resilio Sync alternative offers a similar feature without the paid component
4. How to Transfer Files From Windows to a Linux Virtual Machine
Instead of running a separate PC, it’s common to run Linux or Windows in a virtual machine (VM). But is there a way to transfer files between Windows and Linux when one is installed in a VM?
Fortunately, yes. With VirtualBox, you can create a virtual shared directory for data syncing.
If you’re running Windows in a VM on Linux (or vice versa), VirtualBox is already set up for sharing. Ensure you have the Guest Additions installed on your virtual machine before proceeding.
In the VirtualBox manager, select the VM, then:
- Choose Start > Headless Start (or with the VM running, Devices > Shared Folders)
- Once running, right-click the VM and select Settings > Shared Folders
- Select Machine Folders
- Click the + symbol on the right (or right-click and select Add Shared Folder)
- Browse the Folder Path and find the directory you want to use
- Set a name (if necessary), then OK
- Use the Auto-mount checkbox to ensure the share is available whenever the VM runs
- Click OK again to confirm and exit
When you reboot the VM, the share will be ready to swap data between the host PC and the guest operating system.
There is another option for sharing files between Windows and Linux PCs. However, creating a shared file on one or both systems and then accessing it across a network is unreliable at best.
Sharing Files Between Windows and Linux Is Easy
Whether you’re new to Linux or you find Windows unfamiliar, sharing data between them is easier than you think. Now that you know how to transfer files from Windows to Linux and vice versa, we’d recommend you try all the methods we’ve mentioned above and work out which one you’re most comfortable with.
If you’re syncing data to Linux, there’s a good chance you’re switching from Windows. Don’t worry—it’s easier than you think.
I see this post is very old, but in my search for an answer to this very question, I was unable to unearth a solution from the vast internet super highway. I, therefore, hope I can contribute and help someone as they too find themselves stumbling for an answer. This simple, natural question does not seem to be documented anywhere.
On Windows 10 Pro connecting to Windows 10 Pro, both running OpenSSH (Windows version 7.7p1, LibreSSL 2.6.5), I was able to find a solution by trial and error. Though surprisingly simple, it took a while. I found the required syntax to be
BY EXAMPLE INSTEAD OF MORE OBSCURE AND INCOMPLETE TEMPLATES:
Transferring securely from a remote system to your local system:
scp user@remotehost:DmySrcCodeProjectFooBarsomefile.cpp C:myRepoProjectFooBar
or going the other way around:
scp C:myRepoProjectFooBarsomefile.cpp user@remotehost:DmySrcCodeProjectFooBar
I also found that if spaces are in the path, the quotations should begin following the remote host name:
scp user@remotehost:"DMy Long Folder Namesomefile.cpp" C:myRepoSimplerNamerBro
Also, for your particular case, I echo what Cornel says:
On Windows, use backslash, at least at conventional command console.
Kind Regards.
RocketCityElectromagnetics
How to get a file from my path d:/test.txt and copy it to /etc/var/test/test.txt?
I’ve tried this:
scp d:/test.txt /etc/var/test/test.txt
but that didn’t work.
How do I set the hard disk from where I copy my files?
asked Mar 14, 2014 at 10:30
1
Umm, if you’re using cygwin you want that command to look like
scp /cygdrive/d/test.txt <linux ip>:/etc/var/test/test.txt
Or you can use WinSCP, you’ll probably find that simpler.
answered Mar 14, 2014 at 10:47
The best way to copy files from Windows to Linux using the command line is through pscp. It is very easy and secure. For pscp to work on your windows machine, you need it add its executable to your systems path. Once it is done, you can use the following format to copy the file.
pscp -pw password D:test.txt user@192.168.33.10:/etc/var/test/test.txt
You can refer the following blog post for more information on pscp setup.
http://comtechies.com/2016/02/copy-files-between-windows-and-linux.html
answered Feb 25, 2016 at 10:13
2
Assuming you are on Windows, best way is to download and install cygwin. Get the path to the binary folder and add it to the system path. You can now run Linux commands on your command line.
Open the command prompt and go to the directory where your file is that you want to copy. Run the following command;
scp file.txt root@1.1.1.1:/opt/
- scp — secure copy command
- file.txt — file you want to copy
- root — username used to log onto CentOS machine
- 1.1.1.1 — IP address of CentOS machine. Needless to say your Windows machine and the CentOS machine have to be able to communicate with one another
- :/opt — This is the directory with which you save the file to, I generally save everything to the /opt directory
- Don’t forget the @ between the username and IP Address and the : between the IP Address and directory you are saving the file to
If you need a key to login into the server, enter the following;
scp key.pem file.txt root@1.1.1.1:/opt
For handiness sake I just copy the file I want to copy across to the key file directory, that way you know everything will run smoothly
answered Mar 20, 2014 at 17:15
DanDan
1951 silver badge7 bronze badges
I would highly recommend to use WinSCP if you’re a Windows user. It has a good intuitive interface and gets the job done easily and with no pain.
Download link
answered Oct 1, 2015 at 19:52
AndreiAndrei
1611 silver badge3 bronze badges
to copy a file from windows to linux write:
scp -i privatekey pathFileOnWindows user@publicIp:pathDirectoryLinux
(the colon : is important!)
Example:
//I am located here in my console
C:Usersoscar>
//I’m executing the next command
scp -i C:UsersoscarDocumentsllavesubuntu.pem C:UsersoscarDocumentsindex.html ubuntu@ec2-54-94-247-176.sa-east-1.compute.amazonaws.com:~/
You can puth the full path or location in the path where the file is located. ~/
means the home directory of the user ubuntu
Jenny D
27.5k21 gold badges74 silver badges111 bronze badges
answered Mar 19, 2019 at 3:47
1
If you are on the remote machine:
scp user@hostname:D:text.txt user@hostname:/etc/var/test/test.txt
If you are currently on Windows machine:
winscp D:text.txt user@hostname:/etc/var/test/test.txt
answered Mar 14, 2014 at 10:56
pscp with -pw exposes my password, which I don’t like. The below answer works just like me using scp on linux -> linux.
pscp -scp C:Windowsfoo.txt username@10.0.0.1:/foo/bar
answered Aug 23, 2019 at 22:06
lobilobi
1,0512 gold badges15 silver badges30 bronze badges
First you have to install any ssh client (OpenSSH) which support command line interface for your windows machine:
And add its path to windows Variable:
My Windows System output like below:
Then you will able to execute the same commands on your windows machine
You can copy also complete directory by executing:
scp -r path/to/dir_name/* user@remote-ip:/path/to/destination_dir
To Copy Single File:
scp -r path/to/file_name.zip user@remote-ip:/path/to/destination_dir/
Replace the file extension with your own file.
answered Mar 1, 2016 at 14:44
WinSCP is definitely an useful utility, especially if you want a graphic interface. But if you’re looking for a command line alternative without having to deal with installing cygwin, there’s also pscp
which is part of the PuTTY collection of tools.
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
answered Oct 1, 2015 at 21:25
if you are using windows and want to copy to the linux server then install the WINSCP and just use the drag and drop
answered Oct 15, 2015 at 9:51
OpenSSH is available for PowerShell since 2019. Instructions for installation are available from Microsoft’s Docs site. Instructions for use of OpenSSH utilities are available on OpenSSH project site.
Basically, once you install the OpenSSH suite, scp will work as you are accustomed.
scp user@source:path/to/source/file user@destination:path/to/target/file
where source and destination are hostnames or IP addresses and a path and filename without a host name/address will be treated as local.
answered Apr 5, 2021 at 14:20
Jeter-workJeter-work
8254 silver badges15 bronze badges
SCP <path of the file along with filename and extension> <name of vm>@<ip address>:<path where file needs to be copied>
answered Dec 19, 2022 at 7:49
Each operating system uses its own file system. Windows, for example, uses NTFS on its primary partition; macOS uses its own system, APFS ; and Linux, although it is compatible with a good number of file systems, the most used in most distributions is EXT4 . As each system uses its own formats, it is difficult (and dangerous) to access the partitions of other operating systems. So if we are using Linux and we have to access a file saved on the Windows hard drive, what can we do?
Contents
- Save data to a shared hard drive
- Other ways to access Windows data from Linux
- Restart your computer
- Mount the NTFS hard drive
- Recover Linux data from Windows
- Restart the PC
- Use a program to read EXT4
- Use the Windows Subsystem for Linux
Save data to a shared hard drive
If we want to avoid this type of problem, the best we can do is create a shared drive where we can save the data of all the operating systems that we use. This unit can be a hard drive or partition that we have internal to our own PC or an external hard drive that we have connected to the PC. The important thing is that this drive has a file system that is compatible with both Windows and Linux. And, although we can use NTFS for this, the best we can choose to avoid problems is exFAT .
Both Windows and Linux will be able to read and write to the exFAT disk without problems. This file system is the improved version of FAT32 that eliminates, among other restrictions, the limit of 4 GB per file. Therefore, we can use it as a link between all our operating systems. The important thing is to make sure that we keep all the data there.
Another alternative that we can use is a NAS server . These servers are connected to the network and allow any user connected to it to access the data. They usually mount an SMB / SAMBA server, so the files will be available from both Windows and Linux.
Other ways to access Windows data from Linux
In this case, we are going to see what we can do if we need to access a file from Linux that we have saved on the Windows hard drive.
Restart your computer
The simplest, and safest at the same time, is to restart the computer and return to Windows . By doing so, we will once again have access to all the files that we had saved on that hard drive and, therefore, we will be able to access it. Now that we are in Windows we can choose, either to do what we wanted to do from the Microsoft operating system, or to transfer the file to Linux, either through a pendrive or from the nexus hard drive that we have explained in the previous point .
This is the safest way to do it, since by not entering the Windows hard drive from Linux, we avoid changing permissions or corrupting files, saving us problems. However, it is the slowest method.
Mount the NTFS hard drive
Linux is capable of reading and writing to NTFS drives. The kernel itself has its own controller, and there are other third-party tools for this purpose. Reading files from an NTFS partition from Linux usually works fine, it doesn’t usually give problems. But if we are going to make any changes we run the risk that something does not go well and some data will be corrupted. Windows may be damaged, or we may lose files.
If we know what we are going to do, we can mount the Windows NTFS disk and access all its data. As long as we do not touch anything or modify anything, we can copy (yes, better copy than move) the file or files that we need from this unit to the Linux partition, and thus we can work with it without problems.
It is the fastest method, but the most risky. And it will only be possible if we do not have the disk encrypted with Bitlocker.
Recover Linux data from Windows
What if we use Linux, we go back to Windows and we have forgotten a file? Here we have several ways to re-access the data.
Restart the PC
As in the previous case, the safest and easiest way is to restart the computer and re-enter Linux . Once there, we can copy the file to a pendrive or an external hard drive, and restart again to take it to Linux. It is the longest and most tedious process, but it is the safest.
Use a program to read EXT4
Windows, by default, cannot read or write to Linux EXT drives. Therefore, if we want to access the data, it is necessary to install a program that allows us to do so. There is a very varied software, both free and paid, that allows us to do this. However, most of them are quite outdated programs that, although they can work, they can also give errors.
If we are going to avoid writing in these units, and we only want to pass the data, we can resort to these programs. If not, it is better to find another alternative.
Use the Windows Subsystem for Linux
Microsoft is betting very hard to integrate Linux into Windows. Thanks to the Windows Subsystem for Linux , WSL, it is possible to load a complete Linux instance on top of the operating system, thanks to Hyper-V. With the advent of WSL2, Windows is able to mount and use Linux EXT4 drives as if it were a hard drive more connected to the computer.
If we are advanced users, who have WSL enabled on Windows, and we want to access Linux data from Microsoft’s operating system, this is the best option. Anyway, we hope that Microsoft will simplify this process soon, adding almost native support to EXT4 from Windows.
I’m a CentOS 6
User so I tried this method on CentOS 6
Install samba using
[root@server ~]# yum install samba
Query for confirm
[root@server ~]# rpm -qa samba samba-3.5.10-125.el6.i686
Create a Samba User.
[root@server ~]# useradd sambashare
Now create samba password for username sambashare using smbpasswd command.
[root@server ~]# smbpasswd -a sambashare New SMB password: Retype new SMB password: Added user sambashare.
Create a samba share directory
[root@server ~]# mkdir /share
change the ownership for the share folder
[root@server ~]# chown -R sambashare:sambashare /share/
Open the file /etc/samba/smb.conf
and add the below lines.
[share] comment = Share path = /share writable = yes valid users = sambashare
Start samba service
[root@server ~]# service smb restart Shutting down SMB services: [ OK ] Starting SMB services: [ OK ]
Check your configuration by using testparm
command
. . [share] comment = share path = /share valid users = sambashare read only = No
In windows system type this in run
Now enter samba username and password
You are done