Ubuntu

How to Copy Files From Windows to Ubuntu in WSL on the Same Host

Windows allows installing Linux systems using the Windows Subsystem for Linux (WSL). When you have your Linux system in WSL, you will inevitably need to share files between the two systems. Here, Windows is your host machine, and when you need to transfer large files quickly, your best option is to use a remote method. This guide covers how to copy files from Windows to Ubuntu in WSL on the same host using SSH and the Windows /mnt file system.

Copying Files From Windows to Ubuntu in WSL

If you are used to connecting to your Linux system remotely, you must understand working with SSH, which we will also cover in this guide. However, since our Ubuntu is using Windows as the host, we can workaround the file system and still copy our files.

Method 1. Using the File System

The WSL mounts the C drive of the host, which is our Windows, and you can access other file systems using the mounted drive. In that case, accessing the mounted drive from Ubuntu means we can copy files from Windows to Ubuntu.

Follow the steps below.

Confirm that you can access the mounted drive and all its directories using the command below.

$ sudo ls /mnt/*

You can note the various directories and navigate to the Users folder for more files.

For this case, let’s create a file, linuxtest.txt, on our Windows host from Ubuntu, then try to copy the same file from Windows to Ubuntu using the /mnt

To create the file, use the command below and replace the path to match yours.

$ sudo touch /mnt/c/Users/kyle/Documents/linuxtest.txt

Confirm that the file got created on the Windows host system as in the image above.

Now, copy the file using the command below to the current directory.

$ sudo cp /mnt/c/Users/kyle/Documents/linuxtest.txt .

Initially, we had no file in the current directory, but after the copy command, we can note the file got copied.

That’s how we copy files using the /mnt from Windows to Ubuntu

Method 2. Using SSH and WinSCP

The above methods work well, provided you have the exact path to your files. To avoid the hassle, we can use SSH to connect to the server, Ubuntu, and WinSCP to copy files via a graphical interface.

Follow the steps below.

Install SSH on your WSL Ubuntu machine, and ensure you enable it.

$ sudo apt remove openssh-server

$ sudo apt install openssh-server

Here, you should remove the openssh-server and then reinstall it.

Start the SSH server.

Next, open the SSH configuration file and set ensure you set the PermitRootLogin and the PasswordAuthentication to Yes

$ sudo nano /etc/ssh/sshd_config

With SSH up and running, check your IP address, and you must install the net tools to use the ifconfig command.

$ sudo apt install net-tools

$ ifconfig

Your IP address depends on your network interface, and in this case, it’s the eth0

The next step is to install the WinSCP, and you can download the installer from the official website. Double click the installer and follow the installation wizard selecting the default settings.

Once the tool is installed, open it. You should get a window like the one below.

Your Windows file system will display on the left. Under the hostname, enter the IP you got with the ifconfig command. Also, please enter the username for your Ubuntu system and its password.

Finally, click the login button.

WinSCP will display a screen like the one below authenticating your Ubuntu system using SSH.

Once everything checks out, your Ubuntu will display on the right of the WinSCP window.

From there, locate a file you want to export, right-click on it and choose the Upload option. On the prompt, select where you want to save the copied file to your Ubuntu system.

Alternatively, copy the file, navigate on Ubuntu, and paste it using the keyboard shortcut or by right-clicking. Once uploaded, you will notice the file successfully copied from Windows to Ubuntu on the same host.

Those are the two easy ways of copying files from Windows to Ubuntu WSL on the same host.

Conclusion

This guide covered copying files from Windows to Ubuntu in WSL on the same host. We’ve seen how you can use SSH or the /mnt of the host file system to copy files. Hopefully, you managed to follow along and copy your file from Windows to Ubuntu.

About the author

Denis Kariuki

Denis is a Computer Scientist with a passion for Networking and Cyber Security. I love the terminal, and using Linux is a hobby. I am passionate about sharing tips and ideas about Linux and computing.