Mount Samba Shares Without a password Prompt Andrew Mallett | Posted February 2015

This article demonstrates how to mount a Samba share using the mount_smbfs command without being prompted for a password; a nifty trick for use in an automated shell script. There are a number of ways to achieve this but many solutions involve a reduction in security. I don't want to make a samba share which is available to all and I don't want passwords included in plain text shell script files.

The boxes involved are a Linux Mint server called 'Gateway' with a samba share called docs and a FreeBSD server called 'Goth' which is trying to mount the Gateway share to a local directory called /gatewaydocs..

The command to mount the share from Goth using the username andy is as follows..

/usr/sbin/mount_smbfs -I -N //andy@gateway/docs /gatewaydocs

(Note use of full paths as this will run as a script in cron)

The trick is to use the -N switch which tells the command to look for the username/password credentials in another place. That other place is a file called .nsmbrc which needs to be created in a user's home directory - I use root's own home dir as I set up my crontab -e as root..

vi /root/.nsmbrc

The .nsmbrc file contains two lines which must follow a specific format..


The top line contains the name of the samba server, a colon and the username, both in square brackets with no spaces. Note this line must be in capitals. The second line specifies the user's password.

This can be a very useful way to mount drives between systems without requiring user input, for instance in automated backup routines.