How to scp from linux to windows

To use scp (Secure Copy Protocol) for transferring files from a Linux system to a Windows machine, you need to set up a few things on the Windows machine first, since Windows doesn’t have an scp server by default. Here’s a step-by-step guide:

Install an SCP server on Windows

You can use OpenSSH Server or WinSCP (GUI-based) for SCP functionality. However, we will focus on the OpenSSH method since it’s more common and works in the terminal.

Install OpenSSH on Windows:

If you’re using Windows 10 or later, OpenSSH is already included but might need to be enabled.

  1. Open Settings: Press Win + I to open the Settings app.
  2. Go to Optional Features:
    • Click on Apps or System.
    • Click Optional Features.
    • Scroll down and look for OpenSSH Server.
    • If it is not installed, click Add a feature, find OpenSSH Server, and install it.
  3. Start the OpenSSH Server:
    • Open PowerShell as Administrator.
    • Run the following command to start the OpenSSH server: Start-Service sshd
    • To make it start automatically with Windows: Set-Service -Name sshd -StartupType 'Automatic'
  4. Allow SSH through the Windows Firewall: New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled true -Protocol TCP -Action Allow -LocalPort 22

Find the IP Address of the Windows Machine

To transfer files using SCP, you need the IP address of the Windows machine. You can find it by running the following command in Command Prompt on Windows:

ipconfig

Look for the IPv4 Address under your active network connection.

Transfer Files Using SCP from Linux

Once OpenSSH is set up on your Windows machine, you can use scp from your Linux terminal.

Syntax for SCP:

scp [source_file] [user]@[windows_ip_address]:[destination_folder]
  • [source_file]: Path to the file on your Linux system.
  • [user]: The username on the Windows machine. By default, it’s usually your Windows username.
  • [windows_ip_address]: The IP address of the Windows machine.
  • [destination_folder]: The directory on Windows where you want to copy the file. You can use the full path like C:/Users/yourusername/Desktop/.

Example:

If you want to copy a file myfile.txt from Linux to the Desktop of the user JohnDoe on Windows, run:

scp myfile.txt john_doe@192.168.1.100:/C:/Users/john_doe/Desktop/

After running this command, you’ll be prompted for the password of the Windows user account. Once entered, the file will be copied over.

Troubleshooting:

  • If you have trouble connecting, ensure that the firewall on Windows is not blocking port 22.
  • Make sure you’re using the correct username and IP address.
  • Ensure that the OpenSSH server is running on the Windows machine (sshd service should be active).

That’s it! Now you can transfer files from Linux to Windows using scp