# Ubuntu – How to access the Windows 10 machine from Ubuntu

20.04sambawindows 10

User story follows, just to illustrate better how this is an Ubuntu question 😉

I, as an Ubuntu user (on 20.04.2),

would like to
connect to my Windows 10 machine via a LAN cable (preferably via the SMB protocol)

so that
I can copy/move over downloaded files and documents that I have authored there

because
at the end of the day I want my Ubuntu machine to be the canonical (ha!) home for my documents.

I know this is not a Windows Q/A site, so feel free to not go into details (if you don't want to) about the steps that I need to carry out on the Windows machine, but please, could you at least give a list of steps about the Samba setup as keywords that I can follow and google one by one?

What I need:

Unfortunately it seems I can't just pull over an entire directory and be done with it. Instead, I would like to use a graphical file manager (Nautilus) to "merge" the contents of some select remote directories into their corresponding local ones, and manually resolve any conflicts should they arise.

What I have tried:

I have tried to enable NFS on Windows (because I already have some NFS experience), but have found out that Windows 10 still has support for only NFS 3, and therefore transferable filenames are limited to only ASCII characters; so that's not good.

That's why I'm aiming for Samba.

I ended up following this tutorial:

http://www.bitpi.co/2015/02/16/accessing-a-windows-share-with-a-raspberry-pi/

## On Windows:

The article is for Windows 8, so the network settings UI in Windows 10 was a bit different, but managed to find everything.

• turn on network discovery (for the private network only)
• turn on file and printer sharing (for the private network only)
• choose the folder to share, as well as choose a Windows user to whom the access privileges will be granted to (it can be your normal Windows user), and set up (via checkboxes) which privileges should be granted when accessing via the network
• the little sharing setup window will reveal the "network path" of the shared folder, pay attention to that, will need it when mounting

Finding out the Windows machine's LAN IP address is also necessary: the ipconfig command issued in Powershell reveals it.

My Windows 10 does not set up my LAN network automatically as Private (however, the sharing was set up only for private networks).

Launch Powershell with Administrator rights to fix that:

# This will reveal — among other things — the "Name" of the LAN
Get-NetConnectionProfile

# This sets it private
Set-NetConnectionProfile -Name "the value of 'Name' from the previous command" -NetworkCategory Private


## On Ubuntu:

Prepare a mount point:

sudo mkdir /mnt/my_windows_stuffs


Install cifs-utils, which is sort of a partial drop-in for samba; the smbclient and winbind packages will be installed automatically as its dependencies.

sudo apt install cifs-utils


Mounting with cifs:

sudo mount.cifs //WINDOWS.IP.ADDRESS.HERE/path/on/windows /mnt/my_windows_stuffs/ -o user=WindowsUserNameHere,uid=$(id -u),gid=$(id -g)


Remarks on some select arguments:

//WINDOWS.IP.ADDRESS.HERE/path/on/windows

Note that from the "network path" that Windows suggested (and which contains the Windows machine's name as server identifier), we use only the filesystem path. The machine's name will be replaced by the Windows machine's LAN IP address. It still needs to be preceded by //.

user=WindowsUserNameHere

The above linked tutorial suggested providing an option — in addition to user — for the password too, but that could end up as plain text in ~/.bash_history, which is better avoided.

However, if this password option is omitted, then one will be prompted for it interactively, and it can be entered in a similar fashion as Linux's sudo password.

An additional possibility would be to use the credentials option to point to a file containing the user & password values. This option would be the best fit, when the mount instruction needs to go in /etc/fstab. See more about this in the below linked documentation.

uid=$(id -u),gid=$(id -g)

Without these options the contents of the mounted folder would not be writable, even if on the Windows-side the write permission were granted. It's because even though the mount folder was given to our regular user during our preparation, cifs would still put the content into it as root: all content inside would still be owned by root.

We need to tell cifs to handle the contents on our regular user's behalf.

The options of uid and gid will achieve that. To find out their values up-front, one can run the id -u and id -g commands correspondingly. These will return our regular user's user- and group ID.

This however can be made automatic, with using dynamic substitution in the command itself, as seen in the above snippet.

Note that if Windows is sending ownership information along with the content, the further forceuid and forcegid options (no values needed) might also be necessary.

(I have learned about these latter options from @Huygens' answer on the Unix SE site.)

At this point the desired Windows content should be available in the /mnt/my_windows_stuffs/ directory.

Note that using plain rsync on this mount will be extremely slow. Unfortunately, this is expected. Normal copying however works at reasonable rates.

When done working with these files, the Windows machine can be unbound with:

sudo umount /mnt/my_windows_stuffs/


See more in the mount.cifs documentation.