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.




Comments (2)

nice one
I was founding for this thing and i got it here now i can mount itB-)
#1 - click here - 11/22/2015 - 07:42
Great post

Thanks for this article.
#2 - Michael James - 12/22/2015 - 20:09
E-mail (Will not appear online)
;-) :-) :-D :-( :-o :-O B-) :oops: :-[] :-P
To prevent automated Bots form spamming, please enter the text you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
This comment form is powered by GentleSource Comment Script. It can be included in PHP or HTML files and allows visitors to leave comments on the website.

PHP Script   Disposable Email   Temporary Email