Skip to content

PAM mount: Automatically Mount Network Shares at Login

Introduction

You may need sometimes to automatically mount network shares. This can be done with the pam_mount module.

Installation

For installation:

apt-get install pam_mount

Configuration

pam_mount.conf

Edit the /etc/security/pam_mount.conf file and configure what you need. Here we would like users to have nfs home share to be mounted from the server at logon. Add this line at the end of the file:

volume * nfs my_nfs_server /home/& ~ - - -

You may also need to have other mount points for other things like smb, cifs or fuse:

volume user smbfs krueger public /home/user/krueger - - -
volume * fuse - "sshfs#&@fileserver:" /home/& - - -

Application

You must choose an application to mount automatically your share. For example I choose SSH. When a user logs into SSH it must mount the NFS share, so edit this file:

1
2
3
4
5
6
7
8
9
...
auth       required     pam_env.so envfile=/etc/default/locale
auth       required    pam_mount.so
@include   common-auth
...
@include   common-account
session    required pam_mount.so
@include   common-session
...

Now when you'll login, it will automatically mount your home.