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:

1.2. Environment & definitions

Let's define some environmental variables first.

   1 authfile="$HOME/smbclient-authentication-file.txt"
   2 smb_username='0mp'
   3 smb_password='secret'
   4 max_protocol='SMB2'
   5 workgroup='CORP'
   6 service='\\shareserver\importantfolder'

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:

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 touch "${authfile}"
   2 chmod 0600 "${authfile}"
   3 printf 'username = %s\n' "${smb_username}" > "${authfile}"
   4 printf 'password = %s\n' "${smb_password}" > "${authfile}"

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 2018-11-02...

2.1. Current support

2.2. Future goals of the FreeBSD community

2.3. CIFS

3. See also


CategoryHowTo

MateuszPiotrowski/AccessingSmbSharesWithSambaClient (last edited 2019-12-18 14:00:18 by MateuszPiotrowski)