Samba: On Demand CIFS Mounting of Shares

Write tutorials here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Please don't add support questions to tutorials,start your own thread in the appropriate sub-forum instead. Before you post please read this
altair4
Level 18
Level 18
Posts: 8480
Joined: Tue Feb 03, 2009 10:27 am

Samba: On Demand CIFS Mounting of Shares

Postby altair4 » Mon May 16, 2016 1:49 pm

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

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 Tue Dec 13, 2016 4:27 pm, edited 10 times in total.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.

User avatar
MintBean
Level 6
Level 6
Posts: 1120
Joined: Fri Aug 07, 2015 6:54 am

Re: Mounting Samba Shares using CIFS

Postby MintBean » Mon May 16, 2016 3:36 pm

Thanks Altair- you certainly know your CIFS/Samba!

kwisher
Level 5
Level 5
Posts: 781
Joined: Wed Mar 05, 2008 12:54 pm
Location: Greentown, Indiana USA

Re: Mounting Samba Shares using CIFS

Postby kwisher » Tue May 17, 2016 2:28 pm

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?
The instructions suggested Windows XP or better, so I installed Linux :)

altair4
Level 18
Level 18
Posts: 8480
Joined: Tue Feb 03, 2009 10:27 am

Re: Samba: On Demand CIFS Mounting of Shares

Postby altair4 » Tue May 17, 2016 3:01 pm

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
Level 5
Level 5
Posts: 781
Joined: Wed Mar 05, 2008 12:54 pm
Location: Greentown, Indiana USA

Re: Samba: On Demand CIFS Mounting of Shares

Postby kwisher » Wed May 18, 2016 2:31 pm

Yes, MS 2008 R2 domain. Just playing around to see if I would get any type of performance boost.
The instructions suggested Windows XP or better, so I installed Linux :)

dhopley
Level 1
Level 1
Posts: 6
Joined: Tue Nov 27, 2012 9:45 am

Re: Samba: On Demand CIFS Mounting of Shares

Postby dhopley » Thu May 18, 2017 10:48 am

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


Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 3 guests