25

I have downloaded BASH for Windows 10. How would I navigate to a network address as I would in a Windows environment? I have seen SAMBA mentioned and have downloaded smbclient.

I have tried:

smbclient \\localhost\

I receive the error

ERROR: Could not determine network interfaces, you must use a interfaces config file

I am a novice user of BASH, and see this as an opportunity to be more efficient.

As a bonus please show how I could accomplish some common tasks such as copying files across a network, as well as how to authenticate since this would likely be required for such operations.

2 Answers 2

33

In the latest Windows release "Fall Creators Update" it is possible to mount UNC paths, or any other filesystem that Windows can access, from within WSL.

You can do this with the mount command as usual, with the filesystem "drvfs" provided by WSL:

sudo mount -t drvfs '\\server\share' /mnt/share

Single quotes are useful around the UNC path so that you don't have to escape the backslashes. You can mount on an arbitrary directory; I've used /mnt/share as an example here, but any empty directory will do.

All files will show up with full a+rwx 777 permissions. The real access rights will be checked when you try to access a file, and you can get an error at that point even if it looks like the operation should succeed. Every readable file will be treated as executable.


For locations that require credentials you have three options:

  1. Prior to mounting, navigate to the location using Windows' File Explorer and authenticate. WSL will inherit your credentials and permissions. This is the easiest way for a one-off.
  2. Use the net use command from a cmd prompt, or net.exe use from inside WSL (cd /mnt/c first to suppress a warning). You'll need something like net.exe use \\server\share <PASSWORD> /USER:<USERNAME>. You can use '*' for the password to be prompted instead. Other configurations are shown with net.exe help use.
  3. Use the Windows Credential Manager to set up a stored credential. I've never done this one.

I understand that Samba proper can be made to work under WSL as well, but since the host provides the same functionality I would use the built-in version from Windows when it's available. smbclient is primarily for FTP-style access to SMB servers and retrieving/putting individual files, and it should work when appropriately configured as usual.

-2

This is automatically done on WSL2. On PC running WSL2:

\\wsl$
3
  • 1
    This is the reverse of what the question is asking for (accessing the WSL files via a UNC path, rather than accessing a UNC path from WSL). Apr 1, 2022 at 20:10
  • Lol you are literally on the same computer! Minimize the WSL, navigate to \\wsl$, and copy files to or from windows to WSL! Zero effort. But if you read the question carefully they don't actual say what direction. UNC is just a network path and doesn't imply WSL, or Windows, or any other OS/app. I'm actually rather surprised no one is finding my solution helpful since it's built-in exactly for this purpose.
    – Kevin
    Apr 2, 2022 at 21:56
  • 1
    While on Windows itself (even on the terminal) you can seamlessly use UNC paths and work inside them, this is not possible inside a WSL container (i.e., cd \\myserver\myshare will not work), unless the UNC path is mounted. Your solution is a answer to the question "how can I access files of the WSL containers from windows" not "how can I access a UNC path from within a WSL container"
    – reox
    Apr 14, 2022 at 16:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .