A Little Samba

A friend approached me for some Linux help the other day. He wanted to access an SMB/CIFS share on his network attached storage device (NAS) from his Fedora Linux box. I’d actually done something similar in a former life, so it seemed like a relatively simple problem. I assured him that spending some time learning about autofs would quickly get him to where he wanted to be.

In my case, I set up an offsite Linux laptop to make an hourly connection to the company network via VPN, and mount a Windows share. The script would rsync the contents of the Windows share to a local directory, and disconnect. This setup ran happily for a few years with only minor changes for password updates and such.

My friend was less fortunate than I’d hoped. He found a website with some instructions to create a /etc/auto.cifs file that would automagically connect the necessary shares on reference to a dynamically-created directory hierarchy. It sounded great, but, unfortunately, just didn’t work. I poked at it a little while, but, in the end, went with the technique I knew would work. I document it here for posterity. In some cases, where I say I did something, it had actually already been done in the unsuccessful attempt to get things working.

First, I yum install samba-client. The autofs service had already been installed, or else I would have had to do that, too. Then, I make sure that the NAS device was in the Linux machine’s /etc/hosts file (he doesn’t run a Bind server). I create a directory to act as the base for CIFS shares, /cifs (it could be any new directory, arbitrarily deep in the hierarchy.

Let’s assume that the NAS device is named nas, we’re interested in the SMB share myshare on the device, the username we’ll use to access the share is guido, and guido’s password is sarducci. I create a file named /etc/nas.password with two lines:


and after saving it, chmod it to 0600.

I then create, or modify, /etc/auto.master to read

/net -hosts
/cifs /etc/auto.nas --ghost –timeout=60

The --ghost parameter causes any shares mentioned to show in a directory listing even when they’re not actually connected.

The file /etc/auto.nas looks like this:

myshare -fstype=cifs,rw,credentials=/etc/nas.password ://nas/myshare

The above should be on a single line. Additional shares could be added with the same or different credentials. Make sure that this file and all credentials files are chmoded to 0600.

Once the autofs service has been reloaded, you should be able to see files in /cifs/myshare.


0 Responses to “A Little Samba”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: