How To Transfer File From Windows To Linux Using Command Line – SSH File Transfer Protocol

Using the command line to transfer files from Windows to Linux relies on the SCP protocol. If you are looking for a fast, secure, and reliable way to move data between these two operating systems, the command line is your best friend. This guide will show you exactly how to transfer file from windows to linux using command line, step by step, with no fluff.

You don’t need fancy software or a graphical interface. With just a few commands, you can send files across your network in seconds. Whether you are a developer, a system admin, or a curious user, this method works every time.

How To Transfer File From Windows To Linux Using Command Line

This heading sums up the entire process. The core tool you will use is OpenSSH, which comes with a built-in SCP (Secure Copy) client. SCP uses SSH for encryption, so your files stay safe during transfer. Let’s break it down into simple steps.

Prerequisites For File Transfer

Before you start, make sure you have the following ready. Without these, the transfer will fail.

  • A Windows machine with OpenSSH Client installed. Windows 10 and 11 usually have it built-in.
  • A Linux machine with SSH server running. Most distributions have it enabled by default.
  • Both computers must be on the same network, or you need the Linux machine’s IP address accessible over the internet.
  • The username and password (or SSH key) for the Linux machine.

If you don’t have OpenSSH on Windows, you can install it via Settings > Apps > Optional Features. Search for “OpenSSH Client” and install it. That’s it.

Finding The Linux Machine’s IP Address

You need the IP address of your Linux computer. Open a terminal on Linux and type:

ip a

Look for an entry like “inet 192.168.1.10” or similar. That is your IP. Write it down. If you are using a cloud server, you already have the public IP.

Basic SCP Command Syntax

The SCP command follows this pattern:

scp [options] source destination

For transferring from Windows to Linux, the source is a file on Windows, and the destination is a path on Linux. Here is the exact format:

scp C:\path\to\file.txt username@linux_ip:/path/to/destination/

Replace “username” with your Linux username, “linux_ip” with the IP address, and adjust the paths accordingly.

Step-By-Step: Transfer A Single File

Let’s walk through a real example. Say you have a file called “report.pdf” in your Windows Downloads folder. You want to move it to the “Documents” folder on your Linux machine.

  1. Open Command Prompt on Windows. Press Win+R, type “cmd”, and hit Enter.
  2. Navigate to the folder with your file: cd C:\Users\YourName\Downloads
  3. Run the SCP command: scp report.pdf username@192.168.1.10:/home/username/Documents/
  4. You will be prompted for the Linux password. Type it (nothing will show on screen) and press Enter.
  5. The file transfers. You will see a progress bar and a confirmation message.

That is all. Your file is now on the Linux machine. Check the destination folder to verify.

Transfering Multiple Files Or Entire Directories

Need to move more than one file? Use the recursive option -r. This copies the entire folder and its contents.

scp -r C:\Projects\MyApp username@192.168.1.10:/home/username/backup/

This command transfers the “MyApp” folder from Windows to the “backup” folder on Linux. The -r flag is mandatory for directories.

You can also use wildcards to transfer specific file types. For example, to move all .txt files:

scp *.txt username@192.168.1.10:/home/username/docs/

This is handy when you have many files with the same extension.

Using SCP With A Different Port

Sometimes, the SSH server on Linux runs on a non-default port (not 22). In that case, use the -P option (capital P).

scp -P 2222 file.txt username@192.168.1.10:/home/username/

Replace “2222” with your actual port number. This is common on cloud servers for security.

Transfering Files Using SSH Keys (No Password)

Typing a password every time is tedious. You can set up SSH keys for passwordless authentication. First, generate a key pair on Windows.

In Command Prompt, run:

ssh-keygen -t rsa -b 4096

Press Enter to accept defaults. This creates a public key (id_rsa.pub) and a private key (id_rsa) in the .ssh folder. Now, copy the public key to your Linux machine.

type %userprofile%\.ssh\id_rsa.pub | ssh username@linux_ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Enter your password one last time. After this, SCP commands will not ask for a password. This speeds up transfers significantly.

Alternative: Using Rsync Over SSH

Rsync is another powerful tool for file transfers. It is not native to Windows, but you can use it via WSL (Windows Subsystem for Linux) or install it manually. The command is similar to SCP but offers more features like incremental transfers.

rsync -avz file.txt username@linux_ip:/home/username/

The -a flag preserves permissions, -v gives verbose output, and -z compresses data during transfer. Rsync is ideal for large files or frequent backups.

Common Errors And How To Fix Them

You might run into issues. Here are the most frequent problems and solutions.

  • Permission denied (publickey, password): Your credentials are wrong. Double-check the username and password. Or, if using keys, ensure the public key is correctly added to authorized_keys.
  • Connection timed out: The Linux machine is not reachable. Check the IP address and network connectivity. Also, verify that the SSH service is running on Linux (sudo systemctl status ssh).
  • No such file or directory: The source path on Windows is incorrect. Use absolute paths or ensure you are in the right directory.
  • Host key verification failed: The remote host’s fingerprint changed. Edit the known_hosts file in C:\Users\YourName\.ssh\known_hosts and remove the offending line.

These errors are common, but the fixes are straightforward.

Transfering Large Files: Tips For Speed

Large files can take time. Here are some tips to speed things up.

  • Use compression with SCP: scp -C largefile.zip username@linux_ip:/home/username/. The -C flag enables compression.
  • Limit bandwidth if needed: scp -l 1000 file.txt username@linux_ip:/home/username/. The -l flag limits speed in Kbit/s.
  • Use rsync with partial transfers: rsync --partial --progress largefile.zip username@linux_ip:/home/username/. This resumes interrupted transfers.

For very large datasets, consider using a temporary HTTP server or a dedicated transfer tool like FileZilla with SFTP, but SCP works fine for most cases.

Using Windows PowerShell Instead Of Command Prompt

PowerShell also supports SCP, but the syntax is slightly different. In PowerShell, you need to use the full path or use a different command. Actually, SCP works the same in PowerShell as in Command Prompt. Just type the same command.

However, if you prefer, you can use the scp command directly. It is the same executable. So no worries there.

Transfering Files From Linux To Windows

The reverse process is just as easy. You swap the source and destination. For example, to pull a file from Linux to Windows:

scp username@linux_ip:/home/username/file.txt C:\Users\YourName\Downloads\

This downloads the file to your Windows Downloads folder. The same rules apply for directories and multiple files.

Security Considerations

SCP is secure because it uses SSH encryption. But there are a few things to keep in mind.

  • Never share your private SSH key.
  • Use strong passwords or, better, SSH keys.
  • If transferring over the internet, ensure your Linux firewall allows SSH (port 22).
  • Avoid using root account for transfers. Use a regular user with sudo privileges.

These practices keep your data safe.

Automating File Transfers With Scripts

If you transfer files regularly, write a batch script on Windows. Create a .bat file with the SCP command. Then, double-click it to run. For example:

@echo off
scp C:\Data\backup.sql username@192.168.1.10:/home/username/db_backups/
echo Transfer complete.

Save this as “transfer.bat”. You can even schedule it with Task Scheduler for automatic backups.

Using WSL For A More Linux-Like Experience

If you have WSL installed on Windows, you can use native Linux commands. Inside WSL, the SCP command works exactly as on Linux. This is great for users who prefer the Linux terminal.

Just open WSL, navigate to your Windows files via /mnt/c/, and run SCP. For example:

scp /mnt/c/Users/YourName/file.txt username@linux_ip:/home/username/

This method is seamless and avoids Windows path issues.

Troubleshooting SSH Connection Issues

Sometimes, SCP fails because SSH itself has problems. Test the SSH connection first:

ssh username@linux_ip

If this works, SCP will work too. If not, check the SSH service on Linux (sudo systemctl restart ssh), or check your firewall rules.

On Windows, ensure that the OpenSSH service is running. You can check in Services.msc or via PowerShell: Get-Service sshd.

Conclusion

Now you know how to transfer file from windows to linux using command line. The process is simple, secure, and efficient. Start with a single file, then move to directories and automation. With practice, you will do it in seconds.

Remember, the key is the SCP command and the correct syntax. Use SSH keys for convenience, and always verify your paths. If you hit a snag, check the common errors section above.

Command line file transfer is a skill every tech professional should have. It saves time and gives you control. Go ahead and try it now—you will be surprised how easy it is.

Frequently Asked Questions

Can I Transfer Files From Windows To Linux Without A Password?

Yes, set up SSH keys. Generate a key pair on Windows, copy the public key to the Linux machine’s authorized_keys file. Then, SCP will not ask for a password.

What If SCP Is Not Recognized On Windows?

Install OpenSSH Client from Windows Optional Features. Alternatively, use PowerShell or install a third-party tool like Git Bash, which includes SCP.

Is SCP Faster Than FTP?

SCP is generally slower than FTP due to encryption overhead, but it is much more secure. For local networks, the speed difference is negligible.

Can I Transfer A Folder With Subfolders Using SCP?

Yes, use the -r (recursive) option. For example: scp -r C:\Folder username@linux_ip:/home/username/.

What Is The Difference Between SCP And SFTP?

Both use SSH. SCP is simpler and faster for single transfers. SFTP is more interactive and supports features like listing directories and resuming transfers. For basic needs, SCP is fine.