Q. I want to use our NAS server to store backups. Our NAS supports FTP and CIFS / SMB sharing technology. How do I mount and store files on NAS using FreeBSD? How do I automate entire procedure using a shell script? Is that doable? If so, what's the easiest solution ftp or CIFS?
A. The mount_smbfs command mounts a share from a remote server using SMB/CIFS protocol. You can easily mount NAS share using the following syntax:
mount_smbfs -I 1.2.3.4 //username@nasserver/share /path/to/local/mnt
Mount data share from nas05 nas server at /nas05 directory, enter:
# mkdir /nas05
# mount_smbfs -I 10.1.2.3 //vivek@nas05/data /nas05
You will be prompted for your password. Once this happens you can change to the directory and view the contents using cd and ls command.
# cd /nas05
# ls
# cp /path/to/file .
# ls -l
Where,
- -I 10.1.2.3 : Do not use NetBIOS name resolver and connect directly to host, which can be either a valid DNS name or an IP address.
- vivek : Your user name.
- nas05 : NETBIOS Server Name.
- /data : CIFS share name.
- /nas05 : Local mount point directory.
Avoid password prompt
You need to create a ~/.nsmbrc file as follows:
# vi ~/.nsmbrc
Set username and password as follows:
[NAS05:VIVEK] password=myPassword
Now mount NAS as follows:
# mount_smbfs -N -I 10.1.2.3 //vivek@nas05/data /nas05
The -N option forces to read a password from ~/.nsmbrc file. At run time, mount_smbfs reads the ~/.nsmbrc file for additional configuration parameters and a password. If no password is found, mount_smbfs prompts for it. You need to use the -N option while writing a shell script.
See also:
- See how to mount NAS and backup mysql to nas server - automate backup procedure using a shell script under FreeBSD.
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop












{ 4 comments… read them below or add one }
Hi, Manuel from Malaga, Spain, if you want, you can test FreeNAS proyect, is a minimalist FreeBSD distro specially thinking in NAS, you can find ever VMware virtual machines to test, Very much recommended !!
Best regards, Manuel.
Great info on the smb mount…I’mn relatively new to *BSD, so this was a big help!
Thanks for the tip about the SMB password file – I can now mount my NAS from /etc/fstab instead of manually mounting it each time I boot my workstation!
You can also put the password setting in /etc/nsmb.conf.
To do the equivalent of -I automatically, put:
[SERVERNAME]
addr=x.x.x.x
[SERVERNAME:SHARENAME]
password=myPassword