Previously we have shown you how to remotely connect to your Linux machine from a Windows one (Click here). Now, what if you need to transfer some files between your Windows and Linux systems?
Well, a USB drive comes handy for simple data transfers. For a large number of files at different times, you need another efficient method. Transferring your data between Linux and Windows using your local network is the recommended option. With an easy and quick one time setup, you can share your files between various machines.
File Sharing between Linux and Windows Systems
In this tutorial, we shall walk you through sharing your files between Ubuntu and Windows machines over a local network, and we shall also show you how to transfer files between Windows and Linux on the same PC.
Over the Network
Transferring files between Ubuntu and Windows can be done in many ways, but in this tutorial, we are going to discuss the following popular methods:
- Transfer files between Ubuntu and Windows via the SSH.
- Transfer files between Ubuntu and Windows using Samba.
- Transfer files between Ubuntu and Windows using Shared Network Folders.
Method 1: Transfer Files Between Ubuntu And Windows Via SSH
In this method, you need to install and enable SSH service on Ubuntu. Also, we need an SSH client application on Windows. In this tutorial, we shall be using Putty. Next, we are going to use the command line to share your files across the network.
Step 1. Install the SSH package on Ubuntu using the next command.
sudo apt install openssh-server
Install The Open SSH Package On Ubuntu
Step 2. After installation finishes successfully, you can check the SSH service status using the following command.
sudo service ssh status
The output of the command should look like the below screenshot:
Check The SSH Service Status
If the service is not running, you can use the following command to start it:
sudo service ssh start
Also, to enable the SSH service to start every time your system starts up, you can use the following command:
sudo service ssh enable
Step 3. Install the net-tools package.
sudo apt install net-tools
Install net-tools package
Step 4. Execute the next command to get your Ubuntu machine IP.
ifconfig
Ubuntu Machine IP
Step 5. From your Windows machine, we need an SSH client (which is Putty) and a PSCP. PSCP is considered a secure copy tool that is used alongside with Putty to transfer files securely over a network.
You can download both (Putty and PSCP) from the Putty official website. (Click here.) Kindly note that Putty will need to be installed while the PSCP won’t. You have to put the PSCP.exe in the “C:\” drive to be used, as you should see shortly.
Step 6. Now open the file explorer and use the next command to start transferring your files from your Windows machine to Ubuntu.
c:\pscp "C:\Ubuntu Tutorials\Windows Shared Folder\Windows Shared Folder.txt" hendadel@192.168.1.8:windowssharedfile.txt
Copy File From Windows To Ubuntu Via SSH
Step 7. Next, you should enter your Ubuntu password.
Enter Your Ubuntu Password
Step 8. After entering the password successfully, the command shall copy the text file from your Windows machine to your Ubuntu home. You can check your home directory now, and you should find the file there.
Check The Copied File
Step 9. Now in case you need to transfer your files from Ubuntu machine to Windows, open the file explorer from your Windows machine and use the next command. Be careful, and do not forget the dot at the end of the command.
c:\pscp hendadel@192.168.1.8:ubuntushared .
Copy File From Ubuntu To Windows Via SSH
By executing the previous command, you should enter the password of your Ubuntu machine. Next, the file gets transferred from Ubuntu to the Windows current directory.
File Copied Successfully
Method 2: Transfer Files Via Samba
In this method, we are going to install the Samba package on Ubuntu. Moreover, use the Windows run application to connect to the Ubuntu shared directories.
Step 1. Install the Samba package on Ubuntu using the following command.
sudo apt install samba
Install Samba Package On Ubuntu
Step 2. You can set a password to the samba share as follows.
sudo smbpasswd -a hendadel
Add A User For Samba Share
where hendadel is an Ubuntu user that you shall use while accessing the Ubuntu shared directory.
Step 3. Let’s create a directory that is used for sharing your files.
mkdir /home/hendadel/UbuntuSharedDir
Create Directory For The Shared Data
Step 4. Using your favorite text editor, open the samba configuration file.
sudo vi /etc/samba/smb.conf
Open Samba Configuration File
Step 5. Add the next lines at the end of the samba configuration file.
[UbuntuSharedDir] path = /home/hendadel/UbuntuSharedDir available = yes valid users = hendadel read only = no browsable = yes public = yes writable = yes
The samba configuration file should like the below:
Edit Samba Configuration File
Save and exit the samba configuration file.
Step 6. Restart the samba service using the following command:
sudo service smbd restart
Restart Samba Service
Step 7. From the Windows machine, open the run application from the Start menu and enter the Ubuntu machine IP with the shared directory name as follows.
\\192.168.1.8\UbuntuSharedDir
Remote Access To Your Ubuntu
Press the OK button to continue.
Step 8. A Windows Security message will appear, you should have to enter your samba username and password. Then press the OK button to continue.
Authentication Required
Step 9. Now you should have access to your Ubuntu shared directory, and you can transfer files.
Welcome To Your Ubuntu Shared Directory
Method 3: Shared Network Folders
This is the easiest method among all. In this method, we share any folder from the Windows machine to be visible in the Ubuntu machine.
Step 1. From the Windows machine, right-click on the network connections icon in the right bottom of the taskbar.
Right Click On Network Connections
Step 2. Choose the “Open Network & Internet Settings.”
Open Network and Internet Settings.
Step 3. Next, choose “Sharing Options.”
Open Sharing Options
Step 4. Now from your current network profile, choose the following options:
- Turn on network discovery.
- Turn on file and printer sharing.
Choose Options And Save Changes
Don’t forget to save your changes.
Step 5. Now open your file explorer and go to the directory that you need to share. Right-click on the folder then select Properties.
Open Folder Properties
Step 6. After opening the folder properties, let’s choose the Sharing tab. Also, select the Advanced Sharing button.
Open Advanced Sharing
Step 7. Mark “Share this folder” box.
Check The Share This Folder
In case you need to set permissions on the shared folder like (Read, Write), you can select the permissions button and set your permissions.
Set Sharing Permissions
Press the OK button to continue.
Step 8. Now from the Ubuntu machine, open the file browser.
From Your Ubuntu Open The File Browser
Step 9. From the left panel, choose “Other Locations.”
Open Other Locations
Step 10. In the bottom bar, enter your Windows machine IP and path to the shared folder as follows:
smb://192.168.1.6/Windows Shared Folder
Connect To Windows Shared Folder
Then press the Connect button.
Step 11. An authentication message should appear. Enter your username and password. Press the Connect button to continue.
Enter Your Windows Machine Username And Password
Step 12. Next, you should be able to see your Windows shared folder. Now you can transfer files between the two machines.
Welcome To Your Windows Shared Folder
Transferring files between Windows and Linux on the same machine
Previously, we looked at how we can share files between a Linux PC and a Windows PC over a network. Some of the utilities used included SSH, Samba, and Shared Network Folders. Here, we will look at a relatively similar situation only that this time around, it will be on the same machine.
You might be wondering why can’t we copy files directly from a Linux partition to a Windows partition and Vice-versa? The simple answer is that; It will work for one but doesn’t work for the other. Let’s look at the reasons behind this.
Why it isn’t easy
The NTFS partition format used by Windows doesn’t support Linux file permissions. Therefore, we can’t consider installing Linux on an NTFS partition other than the Ext4. On the other hand, Windows cannot read the Linux file system even though Linux systems can read an NTFS partition. In most cases, the Linux partition is not listed in the “This PC” section on Windows in a dual boot. Therefore, you can copy a file from the Windows partition on Linux but not the vice-versa.
A simple solution
With the above information in mind, we need to find a way to favor both operating systems and wouldn’t pose any data corruption issues. For example, if you delete or alter any file in the Windows partition while accessing it with Linux, there is a high probability that Windows might raise some errors on boot.
Since Linux can’t run on an NTFS or FAT32 partition and Windows can’t read a Linux file system, we will need to configure a third partition that can be accessed by both operating systems. This third partition will contain commonly shared files between the two. Let’s call it the SharedPartition.
We can use other methods to share files, including external storage like USB or online storage like Google Drive and DropBox. However, these are tedious as one will require a reboot to switch from one OS to another while the other method is dependent on bandwidth.
Create a SharedPartition
Whether you have an SSD or Hard drive, we will require at least Four partitions:
- Linux Partition
- Windows Partition
- A SWAP space
- The SharedPartition (NTFS)
I believe you already have the first three. To create the SharedPartition, you can safely check our post on ‘Creating or resizing partitions in Linux.‘ Ensure you format it to NTFS. Additionally, you might need to understand the partition Table used on your Drives. That can be GPT or MBR. Our post on ‘Booting Linux or Windows from a USB drive‘ gives you a comprehensive guide on this. You will also understand the advantage of one over the other.
Up to here, we already have a SharedPartition that can be accessed by both Operating Systems. However, we might need to perform some configurations like Auto-mount on Linux and setting it as the default location for various files.
Configure Auto-Mount on Linux
We will need to execute several commands on the command-line. If you are just getting started with, don’t panic. Please copy and paste the commands as they are below. Our Linux distribution of choice in this post is Ubuntu 20.04 LTS.
Note: Remember to replace the name SharedPartition with the label of your new partition in any of the commands.
Step 1. Install the ntfs-3g driver, which enables Linux to read and write NTFS partitions.
sudo apt install ntfs-3g
Install NTFS-3g
Step 2. Create a directory where we will mount our new partition.
sudo mkdir /media/SharedPartition
Create Mount directory
Step 3. Get the UUID (universally unique identifier) of the new SharedPartition with the command below.
sudo blkid
You should see an output like this.
Know your UUID
Copy the UUID of the SharedPartition. The UUID identifies the partition in the /etc/fstab file.
Step 4. Since we will be editing the /etc/fstab file, create a backup with the command below.
sudo cp /etc/fstab /etc/fstab.backup
Step 5. Execute the command below to edit /etc/fstab using the nano editor.
sudo nano /etc/fstab
You should see a window like the one below. Add the following line at the end but remember to replace the UUID with yours.
# SharedStorage UUID=66E53AEC54455DB2 /media/SharedPartition/ ntfs-3g auto,user,rw 0 0
Edit etc-fstab
After this step, reboot your PC. You should now see the SharedPartition mounted under the ‘Other Locations’ menu.
SharedPartition
Configure your Special Folders (Linux)
Special folders in Linux are those present on your Home directory. They include Desktop, Documents, Videos, etc. Execute the below command to edit their paths.
sudo nano .config/user-dirs.dirs
Special Folders
Now, we need to edit the paths to point to our SharedPartition mounted in /media/SharedPartition. For example, for Downloads, we will add the path “/media/SharedPartition/Downloads” and delete the “$HOME/Downloads” path. After applying the changes, you should have something similar to this:
Special Folders
Save your changes and close the Nano editor.
Configure your Special Folders (Windows)
Step 1. Open the File Explorer and type %userprofile% on the address bar. Hit enter.
User Profiles
Step 2. Select a folder, say Downloads, that you want to access in both operating systems. Right-click and select the properties option.
Step 3. On the pop-up window that opens, select the Location tab.
Location Tab
You will see the default path to your Downloads location.
Step 4. Click on the Move button. That will open a window where you will select your new Downloads path. Navigate to your SharedPartition and choose the Downloads folder already created in Linux. Click on the Select Folder button.
Select Destination Folder
Step 5. Click on the Apply button to set the changes.
You will see a pop-up window prompting you to move the content in the old folder to this new location. Click OK.
Apply Changes
That’s it. You can now proceed to do the same for the other Folders. Now, anything you save on these folders, e.g., Documents on Windows, will be accessible on Linux in the Documents directory.
Using another partition to share files between the two operating systems is the most reliable option since Windows cannot read the Linux file system without using third-party software. With this method, you don’t need to have duplicate files. Both operating systems can read and write on the same partition.
Before you get into this article, let’s read a short description of why?
Everything you do in Linux is fine, imagine you are a windows user like to copy files from your windows to Linux — What might be your first thought to do?
step by step guide in Watch here
Here are the different ways you can copy files from Windows to Linux.
1. Using shared folders in your Linux virtual machine
2. Share data using sync software
3. Securely copy files via SSH
4. Transfer files with FTP
5. Share network folders
Before continue all the 5 options provided, isn’t hard to remember everything at a stretch?
So let’s explore only the first option «Using share folders in Linux Virtual Machine»
Since this article related to Linux Ubuntu — here is Linux command line solution
Introduction
As you work in Linux or windows either way you may have to transfer files from one another. In this article will share in detail tips sharing files from both side. I used a folder called «ShareToUbuntu» between Windows and Linux.
A short to describe below three elements cover up entire process,
1. Setup Windows sharing folder sharing access rights
2. Setup sharing folder path in Virtual Box.
3. Execute mount command for the virtual box share folder.
So what software I have used here?
Windows
Windows 10, Oracle VM Virtual Box
Linux
Linux — Ubuntu 18.04 OS installed in Windows Oracle VM Box.
I’m in Windows 10 OS, installed Oracle VM Virtual Box and installed Ubuntu 18.04 OS.
So how do you actually setup sharing folder in window?
1.Setup Windows sharing folder sharing access rights
Let’s define a folder location you would like to create share folder.
1. Go to your windows explorer, drive C:\
2. Create a folder called example «ShareToUbuntu»
3. Right click folder and properties choose «Sharing» tab
4. Click on «Advanced Sharing» button
5. Tick «Share this folder»
6. Click on «Permissions» button
7. Grant access permission ‘Full Control’, ‘Change’ and ‘Read’ to all
8. Click on «Apply» button — That’s all done
In case you want to skip the above 8 steps; can follow up below image.
2. Setup sharing folder path in Virtual Box
Let’s hope you now can have setup ready as mentioned in setting up share folder in windows directory may be C:\ Drive or D:\ Drive, depends on your choice.
Now let’s get into Virtual Box.
You might question me — why do you have Linux Ubuntu in Virtual Box?
Why not a standalone PC for Linux?
Its again depends on choice, how well to maintain server with low cost, having standalone PC may cause cost effective.
Absolutely zero cost to have Oracle virtual box and Linux ubuntu 18.0 installed.
That’s all about my story, lets get into action.
Go to windows start, search for Oracle Virtual box — Download here
Click on Oracle VM Virtual Box,
Now VM Virtual Box Manager gets opened, choose Ubuntu 18.04 installed OS, and right hand side click «Start» to boot OS.
After clicked on start button, you may need to login as a user.
1. Choose «Devices» menu and click
2. Choose «Shared Folder Settings» sub menu
Now to complete the settings
1. Click on the icon marked in below image number 1
2. Add share window opens up, choose the folder path you created in windows drive (number 2)
3. Remember to choose the share folder «ShareToUbuntu» from Windows drive
4. Finally, click on the «Select Folder» — that’s all
So what happens after that?
This is the expected result as below image.
You should be able to view your share folder path provided.
Until now we almost completed our share folder settings
3. Execute mount command for the virtual box share folder.
Here is the actual action begin from executing a mount command
To open command line window short cut key Ctrl + Alt + T
1. Create a folder called «ShareToUbuntu» in command
~$ mkdir ShareToUbuntu
2. Confirm the folder you created by command list
~$ ls
3. Here you with mounting shared folder execute below command and enter
~$ sudo mount -t vboxsf ShareToUbuntu ShareToUbuntu
4. Since you use sudo command, you must enter your password, that’s all done.
Next what?
Go to your windows shared folder place any file, and come back to Linux terminal to view that.
Demo Execution
I have placed a new file call «Transfer from windows to linux.png»
Now I need to ensure it reflects in Linux Ubuntu 18.04 as well.
Switching to Linux Virtual Machine
As marked in below image .png file has been transferred to Linux.
Introduction
While there are various methods available for file transfers from a Windows system to a Linux system, using the Command lines provides a straightforward and reliable approach. In this guide, we’ll walk you through the step-by-step process, highlighting the necessary commands and techniques to seamlessly transfer your files from Windows to Linux.
Prerequisites
Verify Your Remote Linux Server is Ready
If you have ordered one from Database Mart, you will receive an email containing the information of your VPS, including server IP and login credentials. You can also obtain the information on the overview page in the control panel. Please refer to this guide on how to get server credentials if you need assistance.
Steps to Transfer Files from Windows to Linux Using Command Prompt
Step 1. Open the Command Prompt in Local Windows
Search cmd in the search bar, and double-click the Command Prompt to open it. Or press the Windows key + R, then type cmd or cmd.exe in the Run command box, and press Enter.
Then, you should see the command prompt interface as below.
Step 2. Transfer Files between Local Windows and Remote Linux
Before the transfer, we will explain some terms used in the command. When using the command, you should replace these terms with the actual value.
filename.extension: it’s the name of a file and file extension that’s to be transferred. In this case, we may use mydata.txt and website.txt.
folderName: it’s the name of a folder that’s to be transferred. In this case, we may use the Website folder.
customPort: it’s the custom port you use to connect to your remote Linux server.
localFilePath: it’s the path on your local Windows PC.
username: it’s the username used to log into the remote Linux server.
remoteServerAddress: it’s the server IP of the remote Linux server.
remoteFilePath: it’s the path on the remote Linux server. In this case, we use /home/administrator.
2.1 Transfer a File from Local to Remote Server
For demonstration purposes, we have created a file in the desktop>website named «mydata.txt». First, we need to go to the file’s directory by inputting cd, followed by the file path on our local Windows. In this case, the file is located at desktop\website. Therefore, we enter the following command.
After that, you can see that we navigate to the folder where the file is located.
Then, we use the following command to transfer the «mydata.text» from local Window to the remote Linux server.
scp filename.extension username@remoteServerAddress:remoteFilePath
After entering the command, you will be prompted for the password for connecting to the remote server. Input the password and hit the Enter button, the file will be transferred. In this case, we have transferred the local file mydata.txt (located at desktop/website) to the /home/administrator directory on the remote Linux server.
2.2 Transfer a File from Remote Server to Local
You can run the following command to copy a file from the remote server to your local Windows PC.
scp username@remoteServerAddress:remoteFilePath/filename.extension localFilePath
In this case, we have transferred the mydata.txt (located at home/administrator on the remote server) to the desktop directory on the local server.
2.3 Transfer Multiple Files from Local to Remote Server
The SCP command also allows you to transfer multiple files in a single command. Navigate to the file folder and run the following command.
scp localFilePath/filename1.extension localFilePath/filename2.extension username@remoteServerAddress:remoteFilePath
In this case, we have transferred two local files mydata.txt (located at desktop) and mywebsite.txt (located at desktop/website) to the /home/administrator directory on the remote Linux server.
2.4 Transfer a Folder from Local to Remote Server
Besides files, the SCP command also allows you to securely copy folders between the local and remote server. Use the following command to copy a folder from local to the remote server.
scp -r localFilePath/folderName username@remoteServerAddress:remoteFilePath
In this case, we have transferred the local Website folder, which contains two files mydata.txt and mywebsite.txt, to the /home/administrator directory on the remote Linux server.
2.5 Transfer a File Faster
Adding the -c option after the scp command will compress the file while it’s being transferred. Once the file reaches its destination, it returns to its normal size.
scp -c localFilePath/filename.extension username@remoteServerAddress:remoteFilePath
In this case, we have transferred the local Website folder, which contains two files mydata.txt and mywebsite.txt, to the /home/administrator directory on the remote Linux server.
2.6 Transfer a File Using a Custom Port
The scp command uses the 22 port by default. If you have changed to a custom port, please run the following command to transfer a file. Make sure to capitalize the P.
scp -P customPort localFilePath/filename.extension username@remoteServerAddress:remoteFilePath
In this case, we have transferred the local file mydata.txt to the /home/administrator directory on the remote Linux server using a custom port.
Step 3. Verify the File has been Transferred
Then, Use a preferred editor to open the file. Here, we use the «Nano editor.» In this example, the remoteFilePath is /home/administrator, and the filename.extention can be mydata.txt, mywebsite.txt, and myweb.txt.
nano remoteFilePath/filename.extention
We can also check if the folder has been copied to the remote server. Go to the /home/administrator directory and check if the Website folder is there.
cd /home/administrator ll
Conclusion
In conclusion, transferring files from a local Windows machine to a remote Linux server using the command prompt (CMD) is a powerful and efficient method for managing data. By following the step-by-step guide outlined in this blog, you can establish a secure connection, utilize the SCP (Secure Copy Protocol) command, and successfully transfer files between these two platforms.
Other Methods to Transfer Files between Windows and Linux Server
Last Updated :
23 May, 2024
We need to have Ubuntu installed in our Virtual Box for the purpose of this experiment. The host machine is Windows 10 in the following experiment.
Transfer File From Host Machine(Windows) To Guest Machine(Linux)
1. Method 1: Installing SSH on Ubuntu Terminal and allowing Firewall blockage
Open Terminal in Ubuntu which is installed in Virtual Box and enter the following commands for the given purposes.
Step 1: Installing SSH on the Ubuntu Virtual Machine using the command:
sudo apt install ssh.
Running the command sudo apt install ssh
It creates a secure remote login from one machine to another.
Step 2: Enabling SSH on the Ubuntu Virtual machine allowed the transfer of files over TCP using the default port using the following command:
sudo systemctl enable –now ssh
Running the command sudo systemctl enable –now ssh
Allowing any Firewall blockage using the following command:
sudo ufw allow 22/tcp.
So that Firewall doesn’t block the file transfer from one machine to another.
Running the command sudo ufw allow 22/tcp
Finding the IP address of the machine, which will be used to connect the Linux guest machine with the Windows host using FileZilla later:
ip addr
Running the command ip addr
Conclusion
We have successfully installed and enabled ssh on our Ubuntu machine, enabled Firewall blockage, and also found out our IP address of the Linux(Guest Machine).
2. Method 2: Downloading FileZilla
Download FileZilla Client for Windows 10 that is, in the host machine. Download the FileZilla Client as shown in the image below
Download FileZilla Client on Windows 10(Host machine)
Conclusion
We have successfully downloaded FileZilla in our Windows(Host Machine) in this step.
Method 3: Enabling Shared Clipboard and Drag’n’Drop.
Machine>Settings:
Machine->Settings
General>Advanced>Shared Clipboard->Bidirectional.
General>Advanced>Shared Clipboard->Bidirectional.
Next below Shared Clipboard, we will enable the Drag’n’Drop, which was previously Disabled, by making it Bidirectional,
.Enable Drag’n’Drop
Conclusion
In the VirtualBox, we have enabled “Shared Clipboard”, which won’t allow us to copy and paste between the host and the guest machine, and also enabled “Drag’n’Drop”, which will enable us to drag and drop files and folders from the host to guest and from guest to host.
4. Method 4: Create a folder to be transferred to the Guest Machine (Linux)
Creating a Shared Folder to Transfer Files from Host to VM. We can create any folder or file for transfer purposes here we created a “SharedFolder” named folder.
- Right click mouse button on your windows home screen
- Select “New” and select “Folder” from the right arrow.
- We have named the folder “SharedFolder” here for demonstration purposes.
Right click mouse button on Windows screen-> Select “New”->Select->”Folder”
The folder named “SharedFolder” created
Conclusion
We have successfully created a folder to be transferred to Guest Machine using FileZilla.
5. Method 5: Connect the Ubuntu machine using FileZilla and transfer the folder.
To connect the Ubuntu machine using FileZilla to the Windows Host System, we went to files inside it and created a new site where we had to put in the IP address (which we found in STEP 1), Username, and Password of the Ubuntu machine and choose the protocol to be SFTP, which helps in secure file transmission between remote SFTP server and local client system.
After this, a successful connection between the Windows 10(Host) operating system and the Linux(Guest) operating system in Virtual Box will be set up.
On the left-hand side are the files of the Host machine whereas on the right-hand side will be the files of the Guest machine. We need to drag and drop the file we want to send to the Guest machine as shown below. We have transferred the file “SharedFolder” from the Host machine to the Guest machine.
Transferring files using drag and drop from left to right
As we can see the file “SharedFolder” has been transferred successfully to the Guest machine.
.File transferred successfully
Conclusion
We were successfully able to make a connection between the Host and the Guest machine using FileZilla and were able to transfer a file using it without copy-pasting from Host to Guest.
Are you looking for a way to quickly transfer files from your Windows computer to your Linux computer and back again? The open source PSCP utility makes it easy to transfer files and folders, and of course it’s open source.
Setting your PATH in Windows
Knowing how to set your command path in Windows makes it easier to use a handy utility like PSCP. If you’re unfamiliar with that process, read how to set a PATH on Windows.
Using PSCP
PSCP (PuTTY Secure Copy Protocol) is a command-line tool for transferring files and folders from a Windows computer to a Linux computer.
-
Download
pscp.exe
from its website. -
Move
pscp.exe
to a folder in your PATH (for example,Desktop\App
if you followed the PATH tutorial here on Opensource.com). If you haven’t set a PATH variable for yourself, you can alternately movepscp.exe
to the folder holding the files you’re going to transfer. -
Open Powershell on your Windows computer using the search bar in the Windows taskbar (type ‘powershell` into the search bar.)
-
Type
pscp –version
to confirm that your computer can find the command.
IP address
Before you can make the transfer, you must know the IP address or fully-qualified domain name of the destination computer. Assuming it’s a computer on your same network, and that you’re not running a DNS server to resolve computer names, you can find the destination IP address using the ip
command on the Linux machine:
[linux]$ ip addr show | grep 'inet '
inet 127.0.0.1/8 scope host lo
inet 192.168.1.23/24 brd 10.0.1.255 scope global noprefixroute eth0
In all cases, 127.0.0.1 is a loopback address that the computer uses only to talk to itself, so in this example the correct address is 192.168.1.23. On your system, the IP address is likely to be different. If you’re not sure which is which, you can try each one in succession until you get the right one (and then write it down somewhere!)
Alternately, you can look in the settings of your router, which lists all addresses assigned over DHCP.
Firewalls and servers
The pscp
command uses the OpenSSH protocol, so your Linux computer must be running the OpenSSH server software, and its firewall must allow SSH traffic.
If you’re not sure whether your Linux machine is running SSH, then run this command on the Linux machine:
[linux]$ sudo systemctl enable --now sshd
To ensure your firewall allows SSH traffic, run this command:
[linux]$ sudo firewall-cmd --add-service ssh --permanent
For more information on firewalls on Linux, read Make Linux stronger with firewalls.
Transfer the file
In this example, I have a file called pscp-test.txt
that I want to transfer from C:\Users\paul\Documents
on my Windows computer to my destination Linux computer home directory /_home_/paul
.
Now that you have the pscp
command and the destination address, you’re ready to transfer the test file pscp-test.txt
. Open Powershell and use the dir
command to change to the Documents
folder, where the sample file is located:
PS> dir %USERPROFILE%\Documents\
Now execute the transfer:
PS> pscp pscp-test.txt paul@192.168.1.23:/home/paul
| Password:
End of keyboard-interactive prompts from server
pscp-test.txt | 0 kb | 0.0 kB/s | ETA: 00:00:00 | 100%
Here’s the syntax, word for word:
-
pscp
: The command used to transfer the file. -
pscp-test.txt
is the name of the file you want to transfer from Windows. -
paul@192.168.1.23
is my username on the Linux computer, and the IP address of the Linux computer. You must replace this with your own user and destination information. Notice thatpscp
requires a destination path on the target computer, and:/home/paul
at the end of the IP address specifies that I want the file copied to my home folder.
After you authenticate to the Linux computer, the pscp-test.txt
file is transferred to the Linux computer.
[ Related read Share files between Linux and Windows computers ]
Verifying the transferred
On your Linux computer, open a terminal and use the ls
command to verify that the file pscp-test.txt
appears in your home directory.
[linux]$ ls
Documents
Downloads
Music
Pictures
pscp-test.txt
Copying a file off of a Linux system
You aren’t limited to just copying files to your Linux system. With pscp
, you can also copy a file from Linux onto Windows. The syntax is the same, only in reverse:
PS> pscp paul@192.168.1.23:/home/paul/pscp-test.txt %USERPROFILE%\Documents\pscp-win.txt
Here’s the syntax:
-
pscp
: The command used to transfer the file. -
paul@192.168.1.23:/home/paul/pscp-test.txt
is my username on the Linux computer, the IP address of the Linux computer, and the path to the file I want to copy. -
%USERPROFILE%\Documents
is the location on my Windows computer where I want to save the file. Notice that in copying the file back to my Windows computer, I can give it a new name, such aspscp-win.txt
, to differentiate it from the original. You don’t have to rename the file, of course, but for this demonstration it’s a useful shortcut.
Open your file manager to verify that the pscp-win.txt
file was copied to the Windows C:\Users\paul\Documents
path from the Linux computer.
Image by:
(Paul Laubscher, CC BY-SA 4.0)
Remote copying
With the power of the open source pscp
command, you have access to any computer in your house, and servers you have accounts on, and even mobile and edge devices.
This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.