This article introduces how to access and mount Windows 10 shared folders from a remote network. Previously, I wrote an article about mounting Windows shared share folders on ubuntu 16.04 or 18.04 on a local network.
Ubuntu 18.04でWindows 10の共有フォルダをマウントする方法 windows 10のシェア(共有)フォルダをubuntu16.04でマウント(同期)する
sudo mount -t cifs //192.168.3.19/_sync_ ~/share -o user=ifgm2,pass=hogefuga,dir_mode=0777,file_mode=0777
This time, I tried it on a whim and was able to access shared folders remotely, so I’ll introduce it.
The story is simple: just forward the port used by the shared folder.
what port or ports are used for File sharing in windows? - Super User
According to the above, the port used by Windows 10 shared folders seems to be 445.
When I actually checked the port communication status, it indeed looks like it.
PS C:\pg> netstat -aon | sls -Pattern "192.168.0.167"
TCP 192.168.0.110:445 192.168.0.167:59412 ESTABLISHED 4
TCP 192.168.0.110:54261 192.168.0.167:22 ESTABLISHED 16348
TCP 192.168.0.110:58600 192.168.0.167:22 ESTABLISHED 94772

So, set up port forwarding on the WiFi. Configure it like this:
192.168.0.102:445 -> [publicIP]:8201

The WiFi router I use that can do port forwarding can be referenced below.
光回線工事後、4台のルーターを実際に買って検証した結果導き出された最高のwifiルーターとは
It was fine in my case, but depending on the situation, you may need to configure the firewall at this point to open 445.
Now, to actually mount with the mount command, but to specify a port number with mount, do it like this:
mkdir ~/share01t
sudo mount -o port=8201 -t cifs //[publicIP]/__share__ ~/share01t -o user=hogehoge,pass=hogehoge,dir_mode=0777,file_mode=0777
This should have mounted it.
Also, I was thinking of doing this on Xserver rental server this time, but rental servers don’t have sudo privileges, so it seems you can’t use commands like the above.
It seems you can basically mount, but you can’t use the -o option.
mount: only root can use "--options" option
I’m not well-versed in security, so I’m not certain, but this is probably risky security-wise. If the Windows username and password are broken through brute force, access to the shared folder would be permitted.
I don’t think the communication itself is secure like sshfs, so depending on the situation, the password entered from the command line might leak as is.
It would be nice if fuse and sshfs were allowed in WSL, so we wouldn’t have to do such troublesome and insecure things.