Mount Windows file share in Ubuntu

Doing windows file share mount through Nautilus (GUI) is great, but I find it much more convenient to do it through shell.

Mostly because if you wish to save something to these smb mounts, you could have hard time finding location of the smb file share mount. Currently (Ubuntu 20.04) Nautilus mounts file shares in /run/user/1000/gvfs…

Not every app will be able to access that path.

So, let’s do it through shell.

First we need to install cifs utils.

sudo apt install cifs-utils

Now, before we mount our smb file share, we will have to do one more thing – create new directory inside /media folder on local Ubuntu install we wish to access file share from.

sudo mkdir /media/testshare

Now, it is time to mount smb network file share to our Ubuntu install

sudo mount -t cifs -o user=fileshareuser,password=filesharepass //10.0.0.10/folder /media/testshare

Let’s go through the command

fileshareuser – you should replace this with the username that has read/write access on the network file share

filesharepass – password of the user that has rights to the file share you wish to mount.

//10.0.0.10/folder – remote file share ip and folder you wish to mount

/media/testshare – local folder you wish to mount to.

If you wish to unmount mounted folder

sudo umount /media/testshare

You can also make this fileshare permanent by adding following to your /etc/fstab file

//10.0.0.10/folder /media/testshare cifs username=fileshareuser,password=filesharepass,rw,user,noauto 0 0

If you wish to do this as ordinary user, not root.

Let’s say I run apps under my username (zeljko) and not root account on my Ubuntu. If I wish to save something to the mounted file share which is mounted with sudo mount… I will not be able to do it.

Especially if you created new mount directory with sudo mkdir command – only root will have access to it.

Ok, so I just wish that I can mount network file shares as my user and have read/write access to them.

First, I will create new directory in my home dir to which I will mount network file share.

mkdir /home/zeljko/testshare

Ok, now I will need to find uid and gid of my user (zeljko) I will do it by simply typing in command

id

uid=1000(zeljko) gid=1000(zeljko) is what I need.

Now, we will again mount our network share, but this time a little bit different

sudo mount -t cifs -o uid=1000,gid=1000,username=fileshareuser //10.0.0.10/folder /home/zeljko/testshare

Ok, let’s explain this a bit.

We still need to run mount command as sudo, but we specified uid=1000 and gid=1000 which are values of our local Ubuntu account which we wish to use.

username=fileshareuser is user of the remote file share which have access and rights to it. I haven’t specified password parameter, so I will be asked for a password after I access the share.

Our file share will be mounted to /home/zeljko/testshare

Make sure zeljko has all the rights to that testshare folder.

You will be able to access now that file share as your local user and apps will be able to read and write to it.

If you wish to unmount, command is the same as the above I already mentioned.

Disclaimer