====== SMB Shares With Samba Client on FreeBSD ====== ===== Accessing SMB2 Share on a FreeBSD Machine ===== ==== Install Samba ==== We need to install Samba to get [[https://www.freebsd.org/cgi/man.cgi?query=smbclient&apropos=0&sektion=0&arch=default&format=html|smbclient(1)]] . pkg install samba47 Notes: * I've not tested [[https://www.freshports.org/net/samba48/|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 [[https://www.youtube.com/watch?v=Ji4ux4FWpRU&feature=youtu.be&t=971|FreeBSD Office Hours - May 13 2020: The FreeBSD Foundation (starting 16:11)]] ==== Current support ==== * Shares compatible with SMB1 can be easily mounted with [[https://www.freebsd.org/cgi/man.cgi?query=mount_smbfs&apropos=0&sektion=8|mount_smbfs(8)]] on %%FreeBSD%%. It is not the case for SMB2 and SMB3 shares. * This [[https://www.reddit.com/r/BSD/comments/7pwwez/smb_v2_client_on_freebsd_11/|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 [[https://www.reddit.com/r/freebsd/comments/9z5p2b/mounting_smb_v2v3_shares_gvfs/eaf618p/|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 [[DevSummit/201810|notes from the devsummit 2018-10]]. ==== CIFS ==== * It is suggested to [[https://wiki.samba.org/index.php/Mounting_samba_shares_from_a_unix_client|use CIFS, the Common Internet File System]]. It is not available on %%FreeBSD%%, however. ===== See also ===== * [[https://www.freshports.org/sysutils/fusefs-smbnetfs|sysutils/fusefs-smbnetfs]] * [[https://www.freshports.org/sysutils/mountsmb2/|sysutils/mountsmb2]] * [[https://chromium.googlesource.com/chromiumos/platform2/+/HEAD/smbfs/|FUSE based variant by Google using libsmbclient]] ---- {{tag>HowTo}}