Just moozing

Before you can check your notes, you must make them…

Automount coolness

leave a comment »

Auto mounting of network shares in Linux is very useful. Just mount it into the directory structure and the applications don’t see the difference between local data and network data.

I currently have a setup where I access samba/cifs shares and, more recently, files over ssh using sshfs.


Basic setup

Automount is part of the autofs package

apt-get install autofs

The main configuration files are is /etc/auto.master

$ cat /etc/auto.master | grep -v ^#

This is actually the default auto.master. The “+dir” line says to include *.autofs from /etc/auto.master.d. The last line probably means end-of-file – the docs are not clear on this point.


sshfs mounts

I got inspiration from here. Start by installing sshfs

apt-get install sshfs

Make sure you can ssh to the machine you want to use – that is the first step to making it work.

Create the config file for sshfs

$ cat /etc/auto.master.d/auto.sshfs | grep -v ^#
* -fstype=fuse,uid=${UID},gid=${GID},nodev,nonempty,noatime,allow_other,max_read=65536,IdentityFile=${HOME}/.ssh/id_rsa :sshfs\#${USER}@&\:

and add a line in a /etc/auto.master.d/*.autofs to let it included in the maps.

# cat /etc/auto.master.d/server.autofs | grep sshfs
/mnt/net/ssh /etc/auto.master.d/auto.sshfs

This means that accessing /mnt/net/ssh/myserver will give you access to the files on myserver using ssh.

Note that the key used is the .ssh/id_rsa from the mounting users home directory, and also that any configuration in .ssh/config is ignored. The root user must have the servers in the known_hosts files, otherwise there will be a silent yes/no question related to the fingerprint of the server.


Samba shares

This is an old configuration, so I’m vague on the packages needed, but I think it is cifs-utils.

Create the config file for samba

$ cat /etc/auto.master.d/auto.smb | grep -v ^#
* -fstype=cifs,credentials=${HOME}/.cifs/default,uid=${UID},gid=${GID} ://${SERVER}/&6,IdentityFile=${HOME}/.ssh/id_rsa :sshfs\#${USER}@&\:

and add a line in a /etc/auto.master.d/*.autofs for each server (this is different than the ssh version).

$ cat /etc/auto.master.d/server.autofs | grep smb
/mnt/net/serverA /etc/auto.master.d/auto.smb -DSERVER=serverA
/mnt/net/serverB /etc/auto.master.d/auto.smb -DSERVER=serverB
/mnt/net/serverC /etc/auto.master.d/auto.smb -DSERVER=serverC

In this example, three samba servers are available at /mnt/net/serverX, so in order to access the “home” share, go to /mnt/net/serverX/home. I usually make symlinks in my home folder to e.g. ~/net/serverX_home.



As root

/etc/init.d/autofs stop
automount -f -d

And you get lots of information for your debugging. I found this ubuntu community post, that says something about autofs also.


Written by moozing

March 8, 2015 at 12:00

Posted in Tech

Tagged with , , ,

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: