Centos – autofs does not prompt for password when needed

centoslinux

I am trying to setup an automount point using autofs to mount a samba fileshare. I am using the following syntax in my auto.misc file

mydir    -fstype=cifs,rw,user=myusername ://server.domain/path/to/mount

The problem is that it is denying me with NT_STATUS_WRONG_PASSWORD (seen in /var/log/messages with -verbose turned on). It works if I add my password to the mount options using 'password=secretPass123'. I don't want the password to be stored on disk, so I would like it to prompt me for the password. When I mount it manually using "mount" if I leave out the password option, it does prompt me for the password. How do I get autofs to do the same?

I am using CentOS 6.5.

Best Answer

I do not think you can have autofs prompt you for a password. You typically have to store it in a credentials file and reference it in automount file. This is how I've dealt with it in the past.

Example

share1     -fstype=cifs,rw,noperm,netbiosname=${HOST},credentials=/etc/credentials.txt ://winserver/share1

This file is then locked down like so:

$ ls -l /etc/credentials.txt 
-rw-------. 1 root root 54 Jun 14 12:29 /etc/credentials.txt

containing this:

username=somdom\user1
password=secret123!

It's not ideal but is the best you can get with autofs. The other approach is to defer mounting to the users themselves and let them do it on demand using gvfs.

You can also use pam_mount which I cover in detail in this U&L Q&A titled: Proper way to mount samba share.

References

Related Question