When Ubuntu is installed under WSL, you are asked for a default username and password. This default user is the one that "owns" the shares. If that default user doesn't have access to a file, then you will not be able to access it through \\wsl.localhost\Ubuntu
. The default access permissions for other users' home directories (such as this "noroot" user) are drwxr-x---
, which means that anyone outside the user or their group will not have access.
You should be using that default user for almost all actions in Ubuntu. However, it sounds like you have been using the root user for some reason. It's unclear from your question why that's the case.
One possibility that I can think of is that perhaps you were installing Ubuntu and missed the final prompt for that default user/password. In that case, it wouldn't have been created, and the root user would become the default. See this answer for how to correct that. You've apparently done some of those steps already, but make sure you have the permissions correct.
Most importantly, you probably need to create the /etc/wsl.conf
as mentioned in that answer to set noroot
(or whatever you really want your username to be) to be the default user.
Apart from the user/ownership issues, you could (and probably should) be copying the file directly in Ubuntu, rather than using Windows File Explorer. Let's say that you had the file in your root user's home directory and you wanted to move it to to the noroot user's home directory. That would look something like:
As the root user:
cp /root/file.cpp /home/noroot/
chown noroot:noroot /home/noroot/file.cpp
Or as the regular user:
sudo cp /root/file.cpp /home/noroot/
sudo chown noroot:noroot /home/noroot/file.cpp
As @steeldriver mentioned in the comments, if the file is currently on the Windows drive, then that might look like:
sudo cp /mnt/c/home/yourwindowsuser/Documents/projects/file.cpp /home/noroot/
sudo chown noroot:noroot /home/noroot/file.cpp