Thursday, July 17, 2014

How to mount SMB CIFS Windows shared folder under FreeBSD

This document provides help on mounting SMB/CIFS shares under FreeBSD Operating System.
The mount_smbfs command mounts a share from a remote server using SMB/CIFS protocol. You can easily mount MySharedFolder share using the following syntax:
1mount_smbfs -I //myUser@serverName/mySharedFolder /mnt/mySharedFolder
Where, is the IP address of the remote computer.
myUser is your user name.
serverName is NETBIOS Server Name.
mySharedFolder is CIFS share name.
/mnt/mySharedFolder is the local mount point directory.
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:
1cd /mnt/mySharedFolder
2ls -la
To avoid password prompt, you have to create a .nsmbrc file in your home directory:
1vi ~/.nsmbrc
Set username and password as follows:
Note: Both the hostname and the username need to be in uppercase.
Now mount mySharedFolder as follows:
1mount_smbfs -N -I //myUser@serverName/mySharedFolder /mnt/mySharedFolder
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.
mount_smbfs does not make the mount permanent. If the FreeBSD system is rebooted, you will have to mount the share again. To make the mount occur each time you start the FreeBSD system, you can put an entry in your/etc/fstab file. An example file would look like this:
//myUser@serverName/mySharedFolder /mnt/mySharedFolder smbfs rw,-N,-I192.168.1.1 0 0
Next, you have to add the username and password to /etc/nsmb.conf:

No comments: