Freebsd Mount a NAS via SMB / CIFS

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,

  1. -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.
  2. vivek : Your user name.
  3. nas05 : NETBIOS Server Name.
  4. /data : CIFS share name.
  5. /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:


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 4 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • Manuel R. Fernandez Mesa Jan 27, 2009 @ 6:13

    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.

  • John Darrah Jun 29, 2011 @ 22:48

    Great info on the smb mount…I’mn relatively new to *BSD, so this was a big help!

  • Ewout Aug 17, 2011 @ 7:39

    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!

  • rak Dec 2, 2011 @ 3:09

    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

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum