SMB Shares With Samba Client on FreeBSD
Accessing SMB2 Share on a FreeBSD Machine
Install Samba
We need to install Samba to get smbclient(1) .
pkg install samba47
Notes:
- I've not tested net/samba48.
Environment & definitions
Let's define some environmental variables first.
authfile="$HOME/smbclient-authentication-file.txt" smb_username='0mp' smb_password='secret' max_protocol='SMB2' workgroup='CORP' service='\\shareserver\importantfolder'
Also, let's use a variable to refer to the smbclient(1) command invocation with the default set of arguments:
smb_client="smbclient --max-protocol=${max_protocol} --workgroup=${workgroup} ${service}"
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:
touch /usr/local/etc/smb4.conf
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.
touch "${authfile}" chmod 0600 "${authfile}" printf 'username = %s\n' "${smb_username}" > "${authfile}" printf 'password = %s\n' "${smb_password}" > "${authfile}"
Run smbclient(1) (interactive session)
Run smbclient(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.
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:
echo get '\Files\file.txt' 'file.txt' | ${smb_client}
Here's an example of saving (uploading) a file to the share:
echo put './file.txt' | ${smb_client}
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)
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.
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.
CIFS
- It is suggested to use CIFS, the Common Internet File System. It is not available on FreeBSD, however.