SMB Shares With Samba Client on FreeBSD
1. Accessing SMB2 Share on a FreeBSD Machine
1.1. Install Samba
We need to install Samba to get smbclient(1) .
1 pkg install samba47
Notes:
I've not tested net/samba48.
1.2. Environment & definitions
Let's define some environmental variables first.
Also, let's use a variable to refer to the smbclient(1) command invocation with the default set of arguments:
1 smb_client="smbclient --max-protocol=${max_protocol} --workgroup=${workgroup} ${service}"
1.3. Make sure that smb4.conf exists
First the smb4.conf file has to exist. Otherwise smbclient(1) fails with:
smbclient: Can't load /usr/local/etc/smb4.conf - run testparm to debug it
It is enough to run the following command:
1 touch /usr/local/etc/smb4.conf
1.4. Keep login credentials in a separate file
Now let's create a file to store authentication details. The username and the password may also be provided as command line arguments.
1.5. Run smbclient(1) (interactive session)
Run smbclient(1):
1 ${smb_client}
You should now see a prompt similar to this:
Try "help" to get a list of possible commands. smb: \>
smbclient(1) behaves similarly to ftp(1) in the sense that it starts an interactive shell session.
1.6. Run smbclient(1) (scripting)
It is possible to use smbclient(1) in non-interactive scripts.
Here's an example of downloading a file from the share:
1 echo get '\Files\file.txt' 'file.txt' | ${smb_client}
Here's an example of saving (uploading) a file to the share:
1 echo put './file.txt' | ${smb_client}
2. Research
As of 2020-11-02...
Support for SMBv2 has been discussed during FreeBSD Office Hours - May 13 2020: The FreeBSD Foundation (starting 16:11)
2.1. Current support
Shares compatible with SMB1 can be easily mounted with mount_smbfs(8) on FreeBSD. It is not the case for SMB2 and SMB3 shares.
This Reddit thread (SMB V2+ client on FreeBSD 11 from 2018-01-12) suggests that it is not possible at all to mount SMB shares, even with software available in ports.
It is possible to mount SMB2 and SMB3 shares with GNOME Virtual file system (GVfs). See this Reddit comment for more details.
2.2. Future goals of the FreeBSD community
Actually, there is an interest in bringing in support for SMB3 in the near future. See the notes from the devsummit 2018-10.
2.3. CIFS
It is suggested to use CIFS, the Common Internet File System. It is not available on FreeBSD, however, as of 2024.