Samba: On Demand CIFS Mounting of Shares

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
altair4
Level 20
Level 20
Posts: 11427
Joined: Tue Feb 03, 2009 10:27 am

Samba: On Demand CIFS Mounting of Shares

Post by altair4 »

What I am proposing here is replacing - for often used shares - the current process of File Manager > Browse Network > Windows Network > Host Name > Share > Connect which uses gvfs to a File Manager > Host Name Link > Connect using cifs not gvfs.

The current gvfs / libsmbclient process works more or less but there are advantages to using cifs instead and I want to make this as seamless to the end user as possible.

The best way to get started with this is to do a manual temporary mount first to make sure you can connect and then to automate this so using the terminal is not required. I will present this as a series of templates using these variables:

server = the host name, the mDNS host name, or the ip address of the host that contains the desired share.
share = the name of the share that you want to access
uid=1000 = The "1000" is your user id number. You should run the following command to find the uid number for you:

Code: Select all

id
Preliminaries:

** Make sure cifs is installed:

Code: Select all

sudo apt-get install cifs-utils
** Create a mount point for the share.

--- Place the mount point under /media [will also work in your home directory as in /home/altair/Share]
--- This will induce a udisks response that displays the mount point on the desktop, your file manager, and in your apps.

Code: Select all

sudo mkdir /media/Share
[1] For a Windows share:

[1a] If the share allows guest access:

Code: Select all

sudo mount -t cifs //server/share /media/Share -o guest,uid=1000
[1b] If the share requires a Windows username ( nnn ) and password ( ppp ):

Code: Select all

sudo mount -t cifs //server/share /media/Share -o username=nnn,password=ppp,uid=1000
[1c] And if the Windows OS requires a Microsoft account name ( nnn@something.com ) and password ( ppp )

Code: Select all

sudo mount -t cifs //server/share /media/Share -o username=nnn,password=ppp,domain=something.com,uid=1000
[2] For a Linux or OSX share. It is the same as above but add the "nounix" option:

[2a] If the share allows guest access:

Code: Select all

sudo mount -t cifs //server/share /media/Share -o guest,nounix,uid=1000
[2b] If the share requires a username ( nnn ) and pasword ( ppp ):

Code: Select all

sudo mount -t cifs //server/share /media/Share -o username=nnn,password=ppp,nounix,uid=1000
[3] To unmount any of these shares:

Code: Select all

sudo umount /media/Share
To automate this process you change the syntax, add the noauto and user options, then add lines to /etc/fstab. So in the same order as the manual mounts above the lines would look like this in /etc/fstab:

Code: Select all

//server/share /media/Share cifs guest,noauto,user,uid=1000 0 0
//server/share /media/Share cifs username=nnn,password=ppp,noauto,user,uid=1000 0 0
//server/share /media/Share cifs username=nnn,password=ppp,domain=something.com,noauto,user,uid=1000 0 0
//server/share /media/Share cifs guest,nounix,noauto,user,uid=1000 0 0
//server/share /media/Share cifs username=nnn,password=ppp,nounix,noauto,user,uid=1000 0 0
In use this will be seamless:

*** When you need access to the share simply access the icon in the file manager or in your application and fstab will do the rest
*** When you are done using it you can use the little mount icon next to the name to unmount it if there is one for your desktop or right click it to unmount it.

Bonus Info:

There are different dialects ( versions ) of smb and by default both smbclient and mount.cifs use smb 1.0 ( aka NT1 ) which is actually very old. To make things more efficient and allow for faster file transfer speeds you can make them match the server by adding another option to your line in fstab: vers. So to use one example of this:
//server/share /media/Share cifs username=nnn,password=ppp,uid=1000,vers=3.0,noauto,user 0 0
Possible vers values for different servers:
vers = 2.1 FOR Windows 7
vers = 3.0 FOR Windows 10, Linux, and OSX

EDIT: The Linux Kernel starting with 4.13 changed the default CIFS smb dialect from 1.0 to 3.0 so now we have the opposite problem. If version of Windows or samba is very old you need to pass vers=1.0 in the mount command:
//server/share /media/Share cifs username=nnn,password=ppp,uid=1000,vers=1.0,noauto,user 0 0
Bonus Info II.

Some but not all NAS devices use a version of samba that can only be described as antique. And in their case another option takes affect: sec. Mount.cifs by default uses ntlmssp which Windows and OSX use as standard but for these nas devices you may need to drop the security level down a notch: sec=ntlm. For example:
//nas/nas-share /media/NAS cifs username=nnn,password=ppp,uid=1000,sec=ntlm,noauto,user 0 0
There are other options like dir_mode and file_mode that can be used to expand permissions but believe it or not I tried to make this short.
Last edited by altair4 on Fri Mar 02, 2018 8:31 am, edited 12 times in total.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
MintBean

Re: Mounting Samba Shares using CIFS

Post by MintBean »

Thanks Altair- you certainly know your CIFS/Samba!
kwisher

Re: Mounting Samba Shares using CIFS

Post by kwisher »

Very nice how-to. I tried some of you tips here at work where I mound a Windows 2008 server share but seem to have some issues. My existing fstab line looks like this:

Code: Select all

//10.1.0.67/D$ /media/EHS-FS   cifs    credentials=/root/.smbcredentials,iocharset=utf8,file_mode=0777,dir_mode=0777    0       0
If I remove all after the credentials and add any of your suggestions i get mount errors. Any suggestions?
altair4
Level 20
Level 20
Posts: 11427
Joined: Tue Feb 03, 2009 10:27 am

Re: Samba: On Demand CIFS Mounting of Shares

Post by altair4 »

Well, let's see ................

*** If you have a working fstab expression why change it?
*** Are you part of Domain? That’s above my pay grade.
*** Let's look at the options I used:

-- username and password wouldn't be used since you have them covered in your credentials file.

-- uid=1000 may be a problem with permissions to the share not with mounting the share unless there is no user 1000. I should probably note that the user needs to replace 1000 with his own uid however. You don't need this option anyway because of your dir_mode / file_mode settings.

-- then there is noatuo. The purpose of this HowTo is to specifically not have these shares automounted at boot. I want the shares to mount when required. Sorta like AutoFS used to do but focused only on doing it graphically through the file manager or a given application.

Edit: Actually what I'm really trying to do here is replicate the way the user connects to a share now but replacing the gvfs backend with a cifs backend. And in the process saving a few steps.

-- And user. If you already have the share mounted it has been mounted by the user root so only root can unmount it. Another user cannot mount it until root releases it.

-- Oops, forgot one: vers

Let's see Windows 2008 Server? Which one?: From mount.cifs man pages:
2.0 - The SMBv2.002 protocol. This was initially introduced in Windows Vista Service Pack 1, and Windows Server
2008. Note that the initial release version of Windows Vista spoke a slightly different dialect (2.000) that is not
supported.

2.1 - The SMBv2.1 protocol that was introduced in Microsoft Windows 7 and Windows Server 2008R2.
Those would be my guesses.

EDIT: I re-titled this HowTo and changed the description to better describe what I'm trying to achieve.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
kwisher

Re: Samba: On Demand CIFS Mounting of Shares

Post by kwisher »

Yes, MS 2008 R2 domain. Just playing around to see if I would get any type of performance boost.
dhopley
Level 1
Level 1
Posts: 13
Joined: Tue Nov 27, 2012 9:45 am

Re: Samba: On Demand CIFS Mounting of Shares

Post by dhopley »

Dear Altair ,
Hi , using your helpful guide I managed to set up access to my Plusnet Hub 1 router USB (I believe equivalent to the BT HH5a) , for use with the Gentoo systemrescueCD 'live' disk for backup . Unfortunately I found that the router USB 2.0 was far too slow to make such a backup method practical . My normal OS is Linux Mint 17.3 MATE , which has Samba and cifs-utils preinstalled and so I could thru' the OPEN-ing with Caja progressively of Windows Network : Home : PNHUB1 : USB6 identify that the location of the USB6 was SMB://PNHUB!/USB6 , however after significant trial and error I found an operational correct command line mount (where 192.168.1.254 is the router IP address) , is achieved by :
'sudo mount -t cifs //192.168.1.254/usb6 /mnt/usb6 -o guest,nounix,uid=1000' (without the 's) . I'm posting this as a successful example of following the gudie . Thank you Altair ,
dhopley
Tripple_Delta
Level 1
Level 1
Posts: 34
Joined: Fri Oct 13, 2017 11:09 am

Re: Samba: On Demand CIFS Mounting of Shares

Post by Tripple_Delta »

Nice guide. Worked like a charm.

But .... :-)
As a test I removed the part password=.... This didn't work of course.
Now I try to put it back but no matter what I try, it doesn't work anymore.

????
altair4
Level 20
Level 20
Posts: 11427
Joined: Tue Feb 03, 2009 10:27 am

Re: Samba: On Demand CIFS Mounting of Shares

Post by altair4 »

I cannot reproduce your symptom.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
Tripple_Delta
Level 1
Level 1
Posts: 34
Joined: Fri Oct 13, 2017 11:09 am

Re: Samba: On Demand CIFS Mounting of Shares

Post by Tripple_Delta »

I was able to fix it by mounting in my home directory instead of /mnt/share. Maybe I should try /media/share?

Like this:
//server/share /home/me/share cifs credentials=/home/me/.credentials,user,uid=1000,noauto 0 0
Tripple_Delta
Level 1
Level 1
Posts: 34
Joined: Fri Oct 13, 2017 11:09 am

Re: Samba: On Demand CIFS Mounting of Shares

Post by Tripple_Delta »

YES :-)

/media/share works. No idea why.
For fun I'll try /mnt/share again. (didn't work)
Last edited by Tripple_Delta on Sat Oct 14, 2017 11:45 am, edited 1 time in total.
blockhead47
Level 3
Level 3
Posts: 140
Joined: Wed Jun 15, 2016 4:50 pm

Re: Samba: On Demand CIFS Mounting of Shares

Post by blockhead47 »

Thanks altair4, I was just struggling with this very issue and gave up.
Then discovered this excellent information.

With this info I was able to accomplish almost exactly what I wanted.

This may be off topic, but is there a way to accomplish this same behavior using autofs?
What I am trying to accomplish is not mount the share until it is accessed.
altair4
Level 20
Level 20
Posts: 11427
Joined: Tue Feb 03, 2009 10:27 am

Re: Samba: On Demand CIFS Mounting of Shares

Post by altair4 »

Tripple_Delta wrote:YES :-)

/media/share works. No idea why.
For fun I'll try /mnt/share again. (didn't work)
You missed the subtlety of what I posted:
** Create a mount point for the share.

--- Place the mount point under /media [will also work in your home directory as in /home/altair/Share]
--- This will induce a udisks response that displays the mount point on the desktop, your file manager, and in your apps.
There are two things happening here one playing on the other. By placing the mount point in under /media or $HOME a mount icon is placed on the desktop ( if your desktop allows such a thing ), within the side panel of your file manager, and within most applications. Combine that with the user,noauto option for a cifs mount and the mount icon becomes actionable - click on it to mount - click on it or right click on it to unmount.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
altair4
Level 20
Level 20
Posts: 11427
Joined: Tue Feb 03, 2009 10:27 am

Re: Samba: On Demand CIFS Mounting of Shares

Post by altair4 »

blockhead47 wrote:Thanks altair4, I was just struggling with this very issue and gave up.
Then discovered this excellent information.

With this info I was able to accomplish almost exactly what I wanted.

This may be off topic, but is there a way to accomplish this same behavior using autofs?
What I am trying to accomplish is not mount the share until it is accessed.
There is and I wrote a HowTo on that about a hundred years ago: viewtopic.php?f=42&t=144997

To be honest I now think it's just not worth the effort to set up. I like simple. The method I describe here is simple. Practically, the only real difference between the two methods is that AutoFS automatically umounts the share when not in use.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
Tripple_Delta
Level 1
Level 1
Posts: 34
Joined: Fri Oct 13, 2017 11:09 am

Re: Samba: On Demand CIFS Mounting of Shares

Post by Tripple_Delta »

altair4 wrote: You missed the subtlety of what I posted:
Thanks. I knew I had to look into the details. :-)
Tripple_Delta
Level 1
Level 1
Posts: 34
Joined: Fri Oct 13, 2017 11:09 am

Re: Samba: On Demand CIFS Mounting of Shares

Post by Tripple_Delta »

altair4 wrote: There is and I wrote a HowTo on that about a hundred years ago: viewtopic.php?f=42&t=144997

To be honest I now think it's just not worth the effort to set up. I like simple. The method I describe here is simple. Practically, the only real difference between the two methods is that AutoFS automatically umounts the share when not in use.
To me this is more then worthed the effort. I like this sollution even more since now there is full control for every user on the system. Tomorrow I’ll test this with VPN and maybe have a sollid setup with files in one place.

Thanks altair4
User avatar
lsemmens
Level 11
Level 11
Posts: 3936
Joined: Wed Sep 10, 2014 9:07 pm
Location: Rural South Australia

Re: Samba: On Demand CIFS Mounting of Shares

Post by lsemmens »

I tried the cifs command and get a "not implemented yet" response

Code: Select all

 sudo mount -t cifs smb://server/video /home/leigh/Documents/Shares -o guest,nounix,uid=1000
Mounting cifs URL not implemented yet. Attempt to mount smb://server/video
Which did not work, what am I missing?

Mint 18.3 Cinnamon
Fully mint Household
Out of my mind - please leave a message
User avatar
now3by
Level 2
Level 2
Posts: 68
Joined: Mon Jan 23, 2017 1:56 pm

Re: Samba: On Demand CIFS Mounting of Shares

Post by now3by »

remove smb:

Code: Select all

sudo mount -t cifs //server/video /home/leigh/Documents/Shares -o guest,nounix,uid=1000
Linux...
bigverm23

Re: Samba: On Demand CIFS Mounting of Shares

Post by bigverm23 »

great tutorial - is there something similar for that of NFS?

cant seem to find it anywhere.
altair4
Level 20
Level 20
Posts: 11427
Joined: Tue Feb 03, 2009 10:27 am

Re: Samba: On Demand CIFS Mounting of Shares

Post by altair4 »

That I cannot help you with. I haven't used NFS since the Boer Wars :)
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
bigverm23

Re: Samba: On Demand CIFS Mounting of Shares

Post by bigverm23 »

doh! I've been using CIFS with my FreeNAS shares, but its terribly slow to load from my Linux box...so looking into NFS, just want to make sure the SMEs lead me in the right direction!
Post Reply

Return to “Tutorials”