HowTo: Auto Mounting Samba Shares Using AutoFS

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
dclement

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by dclement »

Here it is:

Code: Select all

daniel@e6330v ~ $ cat /etc/auto.master
#
# Sample auto.master file
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# For details of the format look at autofs(5).
#
#/misc	/etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
#	"nosuid" and "nodev" options unless the "suid" and "dev"
#	options are explicitly given.
#
#/net	-hosts
#
# Include /etc/auto.master.d/*.autofs
#
+dir:/etc/auto.master.d
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
/mnt/Samba /etc/auto.sambashares --timeout=30 --ghost
+auto.master
daniel@e6330v ~ $ 
But wait: I'm running Linux Mint Debian! (a link on the LMDE forum led me to your howto -- just noticed it was under the regular edition forum). Does it still apply to LMDE?
altair4
Level 20
Level 20
Posts: 11453
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by altair4 »

I don't do Debian - life's too short. But AutoFS has literally been around for 25+ years so I don't know how even Debian can interfere with it.

Everything seems to be in order here -- well, it matches my HowTo anyway. Um ...

*** Make sure cifs-utils is installed.
*** Make sure you are uid=1000
*** This should also have affected your manual mount but NAS's are tricky little things because they tend to use older versions of Samba so try changing your sambashares file to this:
public fstype=cifs,rw,username=daniel,password=<mypassword>,uid=1000,iocharset=utf8,sec=ntlm ://192.168.0.10/public
And restart the service:

Code: Select all

sudo service autofs restart
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
dclement

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by dclement »

altair4 wrote: [...]
*** Make sure cifs-utils is installed.
It was installed, as part of the tutorial.
*** Make sure you are uid=1000
I checked that too.
[...] NAS's are tricky little things because they tend to use older versions of Samba
Actually it's a Synology NAS, pretty outdated but always trouble-free.
[...] so try changing your sambashares file to this:
public fstype=cifs,rw,username=daniel,password=<mypassword>,uid=1000,iocharset=utf8,sec=ntlm ://192.168.0.10/public
Done, here is what it looks like now:

Code: Select all

daniel@e6330v ~ $ cat /etc/auto.sambashares 
daniel fstype=cifs,rw,username=daniel,password=<mypassword>,uid=1000,iocharset=utf8,sec=ntlm ://192.168.0.10/daniel 
public fstype=cifs,rw,username=daniel,password=<mypassword>,uid=1000,iocharset=utf8,sec=ntlm ://192.168.0.10/public
And restart the service:

Code: Select all

sudo service autofs restart
Alas, it's the same as before. Only thing I can think of, the NAS doesn't have a guest account enabled. But since I'm not using the "guest" option, I doubt it matters.
altair4
Level 20
Level 20
Posts: 11453
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by altair4 »

Turns out I had LMDE in a VBox guest set up that I hadn't updated in a very long time and forgot about so I tried it and it worked just as the HowTo stated. But that was before I realized there was 874 MB of updates waiting for me. I'll spare you the details of the 4 hours spent, the expletives, and the terminal work involved in this but when it was all done autofs wouldn't do jack.

Debian or at least the level of Debian in LMDE is different from the Ubuntu based system in regards to authentication.

For example if I wan't to to access a guest share I can't just do this:
server-share -fstype=cifs,rw,uid=1000,iocharset=utf8 ://server/share

And I can't use this:
server-share -fstype=cifs,rw,uid=1000,iocharset=utf8,username=guest ://server/share

And if I try this:
server-share -fstype=cifs,rw,uid=1000,iocharset=utf8,username=guest,password= ://server/share
I get:
"server-share" could not be found. Perhaps it has recently been deleted.
But if I construct the auto.sambashares entry this way:
server-share -fstype=cifs,rw,uid=1000,iocharset=utf8,credentials=/home/altair/secret.txt ://server/share

Where /home/altair/secret.txt contains:
username=guest
password=<put a single space after the = sign>

It works

So I moved on to a share that requires real credentials and had the exact same problem when I have the username and password options in the sambashares file. So I created one this way:

Code: Select all

server-share2 -fstype=cifs,rw,iocharset=utf8,credentials=/home/altair/secret2.txt,uid=1000 ://server/share2
Where secret2.txt had the actual credentials set:

Code: Select all

username=altair
password=altairspw
And that worked.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
dclement

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by dclement »

Success! That was it, auto.sambashares wanted the credentials to be in a separate file. (I was thinking of doing that anyhow, but perhaps only later).

Needless to say this is far superior to the GVFS method, because the mounted shares are immediately visible in the file-open/save dialogs. Even LibreOffice 4.1 regained the ability to open documents across the network, which it had lost.

Thanks a lot for taking the time to explain this in so much detail. Perhaps I could add "solved" just to my first post in this thread? I think I'll post again in the original LMDE thread, to make sure that other LMDE users read your last post.

BR, Daniel
dclement

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by dclement »

Well... I spoke too fast.

I was unable to reproduce the successful setup from the test PC to my main PC. I ran into the same syndrom:
"server-share" could not be found. Perhaps it has recently been deleted.
I'm confused, because
1) I put the very same parameters into the config files (I even confirmed with Meld that they were identical). Same folders, same credentials file.
2) The overall config of this PC is exactly similar to the one used for testing: LMDE, XFCE... It's just lagging behind in updates (UP8 not applied) and doesn't have Mate, but both file browsers Thunar and Nautilus have the same problem.

Perhaps the UP8 batch of updates will fix that. I'm not planning to apply it until the latest 2014 ISOs are out -- I'm careful with that PC. So I'll try again in a couple of weeks.
altair4
Level 20
Level 20
Posts: 11453
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by altair4 »

Now you know why I don't like dealing with Debian directly - at least not Debian pointing to Testing. :wink:

Since UP8 forced us to move the credentials out of the map file and into separate file to get this to work did you try putting the credentials back in the map file itself for the machine at UP7?
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
dclement

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by dclement »

altair4 wrote:Since UP8 forced us to move the credentials out of the map file and into separate file to get this to work did you try putting the credentials back in the map file itself for the machine at UP7?
We didn't know for sure whether it was Debian or UP8. NOW we know :wink:

That was it, this syntax
public fstype=cifs,rw,username=daniel,password=<mypassword>,uid=1000,iocharset=utf8,sec=ntlm ://192.168.0.10/public
(with the sec=ntlm option) works pre-UP8.

Still, I refuse to blame Debian for this, there are soo many other advantages (but perhaps I should wait to have UP8'd my main PC...)

Thanks a lot again, altair4.
mbohets

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by mbohets »

I see that all login names and passwords are in plain text, is there a way to use encrypted password files in order to boost security ?
altair4
Level 20
Level 20
Posts: 11453
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by altair4 »

Not that I'm aware of. One uses credentials either in the map file or as a separate credentials file the way it was traditionally used when automounting in fstab - by making it accessible only to root.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
dclement

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by dclement »

Hmm... I'll be a bore again, but I'm afraid I'm not done with autofs. I had only checked browsing through the folder structure. Only when I needed to copy files for real, I noticed that the copy failed because of permission denied. As if the autofs-mounted folders were read-only. Yet, it's definitely "rw" in my auto.sambashares file.

OTTH, if I "browse network" from the file manager, I see the same shares, the very same directory structure, but I can write to them.

So I'm thinking of permissions problem. I looked at them, comparing both cases. The shares are owned by root. But in the 1st case (autofs) the access is read-only, whereas in the 2nd it's read-write.

I tried to make myself the owner of a share, grant r+w rights, but I still can't get that to work :(
altair4
Level 20
Level 20
Posts: 11453
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by altair4 »

That I cannot reproduce on my LMDE UP8 system or any other system here.

I suppose theoretically there's a conflict with server causing you to add another option - nounix.

EDIT: Well ... unless you are trying to access the mountpoint from a user other than uid=1000 of course.

But other than that it looks like you're stuck with gvfs. Sorry.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
dclement

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by dclement »

Sorry, just seen your latest edit. It's not that bad after all: it's only the top shares (e.g. ://server/share/) that are not writable. The subfolders (://server/share/folder) are writable indeed.

So my problem is easily worked around, till I perhaps come across a miracle solution. But it could well be a "feature" of my Synology NAS, which are definitely outdated.
michaelzap
Level 3
Level 3
Posts: 166
Joined: Sat Sep 11, 2010 9:32 pm

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by michaelzap »

Hello again -

After quite a while of using AutoFS with no issues whatsoever, suddenly I'm having trouble. I recently updated my Debian file server to unstable and switched the DE to Mate, but these problems seem to have appeared a few days after that. What's happening is that my (Ubuntu-based, Qiana) Mate laptop is suddenly losing its Samba mount to the Debian file server only many, many times a day (it's infuriating!).

I do have some general network issues with this laptop, as it sometimes loses its wifi connection (it's a new Realtek chip, and I haven't found a complete solution to its bugginess yet). But that has been true since I had this laptop, and I never had Samba issues before. So I'm trying to figure out what update or change has messed things up.

I see the following error frequently in my kernel log:

Jul 3 10:59:04 bangarang kernel: [85827.891719] Status code returned 0xc0000001 NT_STATUS_UNSUCCESSFUL
Jul 3 10:59:04 bangarang kernel: [85827.891737] CIFS VFS: Send error in SessSetup = -5
Jul 3 10:59:04 bangarang kernel: [85827.891932] CIFS VFS: cifs_mount failed w/return code = -5

It's just the Debian file server that is unmounted (my other NAS shares still work). But if I try to view the file server from a Windows laptop, it doesn't seem to have any issues. So far it seems like a combination of my Mate laptop and the file server.

What I've been doing when this happens (constantly) is to run "sudo service autofs restart" in a terminal, but it often won't work the first time (usually it will after two or three times). I've tried increasing the timeout value in auto.master, and I added sec=ntlm to the mount in auto.sambashares, but that hasn't helped. Here is the mount that's failing:

colmena -fstype=cifs,rw,username=zap,password=my-password,uid=1000,iocharset=utf8,sec=ntlm ://192.168.0.140/shares
(the ip address is correct and set by my router for this MAC address)

Any ideas as to what might be happening or how I can track it down?

THANKS in advance for your help!
altair4
Level 20
Level 20
Posts: 11453
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by altair4 »

Like I said before I really don't do Debian and now that you moved to Debian Unstable that goes double.

For what it's worth I would abandon AutoFS and connect to the server a different way.

Add a line in your /etc/fstab that mounts the Debian server:

Code: Select all

//192.168.0.140/shares /mnt/DebianServer/shares cifs username=zap,password=my-password,uid=1000,user,noauto 0 0
*** You would have to create the /mnt/DebianServer/shares mount point first.
*** The "noauto" tells the system not to mount this remote share at boot.
*** The "user" option allows an ordinary user to mount - this option is only relevant if "noauto" is used.

Then after you login you run the following command to mount:

Code: Select all

mount /mnt/DebianServer/shares
And this to unmount:

Code: Select all

umount /mnt/DebianServer/shares
I did go through my notes before posting and did see that error message before - in 2004. Crappy note taker at the time but it had something to do with too many simultaneous connections to the server. It was in my "Fixed" folder but unfortunately I apparently didn't bother to write down what I did to resolve it.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
michaelzap
Level 3
Level 3
Posts: 166
Joined: Sat Sep 11, 2010 9:32 pm

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by michaelzap »

I'm afraid that by saying this I'll jinx it, but this issue seems to be resolved. I did three things yesterday, one of which must have done the trick:
  • I ran a dist-upgrade on the Debian file server (although I didn't see any Samba packages in the update list)
  • I added "security=user" to my Samba config file on that server
  • I changed the timeout value in auto.master to a full hour (3600 seconds)
I have no idea which of these things (or what else) may have fixed this, but damn am I glad that it's fixed!

Thanks again for your help!
kb5050

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by kb5050 »

I tried this versus gigolo and I cannot seem to get it to do anything. There are no errors coming up.
No mounted shares appear or can be used in any programs either.
Is this method compatible with Linux mint 17 64 bit Qiana MATE desktop?
The one glitch with gigolo is when you first start up the system it seems to forget the Keyring password. Not always. Well always unless you use the fuse to your account. i.e.
sudo username -add fuse
replacing username with your login name as root
I may have that all wrong because I basically copied out of the gigolo guide I found on here.
gigolo works great otherwise. I thought once upon a time you could do the same thing manually by simply creating bookmakrs, but having automount is the reason to make use of it. This is the 1 of 3 things that need changing in Linux to make it fully enjoed by the masses.

One is that your HAVE to alter samba to have wins resolution last in the search order or your get the dreaded timeout errors. (Simple change to smb.conf
The other is if dual booting to setup a GUI based tool to alter Grub2 menu to allow whatever OS you desire to default to, and include some sort of splash image by default. And lastly support for more hardware, such as scanners and modems. Especailly modems, which really only useful to send faxes. But most scanners have no drivers for them to allow a wider selection of hardwaer. Yeah I guess that is about it. Everything else is pretty much perfect. Oh they do need to include a GUI based way to switch among tasks rather than having to use ALT-TAB key all the time.
UI kniow there is or must be some option or tool for that, but it should be there by default.

Not that I am trendy but a "home" version of Linux Mint should be born. One that removes all the confusing and mostly useless to average user stuff. By this meaning all the networking when really the use just wants basic Windows and Linux simple file sharing and nothing beyond that. Most people have no idea what ssh and ftp means. They grew up in a windows or mac world where everything is just handed to you in plain english pop up boxes. Simplicity is better even for those who know their way around the router..
altair4
Level 20
Level 20
Posts: 11453
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by altair4 »

There appears to be only one question in your post:
kb5050 wrote:Is this method compatible with Linux mint 17 64 bit Qiana MATE desktop?
To find out I just installed LM17-Mate. The relevant part of auto.master is this:
tester1@vm17-0mate ~ $ cat /etc/auto.master | grep Samba
/mnt/Samba /etc/auto.sambashares --timeout=30 --ghost
My auto.sambashares is this:
tester1@vm17-0mate ~ $ cat /etc/auto.sambashares
bravo-Downloads -fstype=cifs,rw,uid=1000,iocharset=utf8 ://bravo.local/downloads
And upon access I can see the "Downloads" share of my bravo server:
tester1@vm17-0mate ~ $ ls -l /mnt/Samba/bravo-Downloads
total 68608
drwxrwxr-x 2 tester1 tester1 0 Apr 21 08:35 AdobeReader
drwxrwxr-x 3 tester1 tester1 0 Feb 15 2012 AirPrint
-rwxrwxrwx 1 tester1 tester1 1529856 Feb 10 2012 BootitNG_187.ISO
-rwxr--r-- 1 tester1 nogroup 6211 Feb 13 2012 Classic Samba Shares.txt
lrwxrwxrwx 1 tester1 tester1 8 Mar 21 12:26 COMMON -> /COMMON/
-rw-rw-r-- 1 tester1 tester1 36 Feb 23 2013 Config
-rw------- 1 tester1 root 84152 May 3 15:12 dead.letter
Um ... yes. Yes, it is compatible with Linux mint 17 MATE.

As for the rest of your post my suggestion is to offer your thoughts in some other section of the forum or perhaps the community site.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
safetycopy

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by safetycopy »

Hi,

Your guides have really helped me - thanks!

I have a question about AutoFS.

At the top of this guide you mention that you should have a working Samba share. Then, later in the guide, you say that AutoFS will create the mount points needed. I'm a little confused how to proceed from my current state of having a working Samba share that I can mount from the terminal, to converting this to use AutoFS instead.

Currently I have a mount point on my server (Debian Wheezy) at /mnt/Storage/dan that I can mount from a client (Linux Mint 17 XFCE) terminal. I'd like to switch that to use AutoFS, so do I need to delete the mount point (directory) and share configuration from smb.conf and set a map file up instead?
altair4
Level 20
Level 20
Posts: 11453
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by altair4 »

AutoFS can create the necessary mount points for you automatically but it doesn't conflict if you already created one.
Currently I have a mount point on my server (Debian Wheezy) at /mnt/Storage/dan that I can mount from a client (Linux Mint 17 XFCE) terminal. I'd like to switch that to use AutoFS, so do I need to delete the mount point (directory) and share configuration from smb.conf and set a map file up instead?
You don't have to do anything on the server.

Why not post the mount command you use to access the server from Mint and we'll use that as an example of how you would mount it using AutoFS?
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
Post Reply

Return to “Tutorials”