How to copy files from Windows to Ubuntu in WSL on the same host

“Windows allows Linux systems to be installed using the Windows Subsystem for Linux (WSL). Having your Linux system in WSL inevitably involves sharing files between the two systems. Here Windows is your host machine and if you need to transfer large files quickly, using a remote method is the best option.”

This guide describes how to copy files from Windows to Ubuntu in WSL on the same host using SSH and the Windows /mnt file system.

Copy files from Windows to Ubuntu in WSL

If you’re used to connecting to your Linux system remotely, you need to understand how to work with SSH, which is also what we’ll cover in this guide. However, since our Ubuntu is using Windows as the host, we can bypass the file system and still copy our files.

Method 1. Using the file system

WSL assembles the C drive of the host, which is our Windows, and you can access other file systems through the mounted drive. In this 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 of its directories with the following command.

$ sudo ls /mnt/*td>

You can note the various directories and navigate to them user 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 by using the /mnt

To create the file, use the following command, replacing the path to match yours.

$ sudo touch /mnt/c/user/kyle/documents/linuxtest.txt

Confirm the file has been created on the Windows host system as shown in the image above.

Now copy the file to the current directory using the following command.

$ sudo see /mnt/c/user/kyle/documents/linuxtest.txt .

Initially we had no file in the Current directorybut after the copy command, we can see that the file has been copied.

Here’s how we copy files with the /mnt from Windows to Ubuntu

Method 2. Using SSH and WinSCP

The above methods work fine 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 through a graphical interface.

Follow the steps below.

To install SSH on your WSL Ubuntu computer and make sure you activate it.

$ sudo apt removes openssh-server

$ sudo suitable To install openssh-server

Here you should remove them openssh-server and then reinstall.

Start the SSH server.

Next, open the SSH configuration file and make sure you have the Allow root login and the password authentication to Yes

$ sudo nano /Etc/sh/sshd_config

If SSH is running, check your IP address and you need to install it net tools which to use ifconfig command.

$ sudo suitable To install net tools

$ ifconfig

Your IP address depends on your network interface, and in this case it is eth0

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

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

Your Windows file system is shown on the left. Under the hostname, Enter the IP you got from the ifconfig command. Also, enter the username for your Ubuntu system and its password.

Finally click on the registration Button.

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

Once everything is checked out, your Ubuntu will appear in the WinSCP window on the right.

Locate a file there that you want to export, right click on it and select the upload Possibility. At the prompt, choose where you want to save the copied file on your Ubuntu system.

Alternatively, you can copy the file, navigate to Ubuntu, and paste it using the keyboard shortcut or right-click. After uploading, you will find that the file has been successfully copied from Windows to Ubuntu on the same host.

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

Conclusion

This guide has covered copying files from Windows to Ubuntu in WSL on the same host. We’ve seen how you can use SSH or /mnt of the host filesystem to copy files. Hope you managed to join in and copy your file from Windows to Ubuntu.

Related Posts