smbclient is the command that we want to use for testing

## smbclient comes with the smbclient package
which smbclient
# /usr/bin/smbclient
dpkg -S /usr/bin/smbclient
# smbclient: /usr/bin/smbclient

First get the share names with (I use -N to omit the password, most often you dont need a password to list the shares with samba)

smbclient -L 10.39.2.11 -N
# Unknown parameter encountered: "force writeback"
# Ignoring unknown parameter "force writeback"
# WARNING: The "null passwords" option is deprecated
# Unknown parameter encountered: "reverse sendfile"
# Ignoring unknown parameter "reverse sendfile"
# 
# Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.0.5]
# 
#         Sharename       Type      Comment
#        ---------       ----      -------
#        all-data        Disk      data
#        IPC$            IPC       IPC Service (3C833A0300244)
#Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.0.5]
#
#        Server               Comment
#        ---------            -------
#
#        Workgroup            Master
#        ---------            -------

NOTE: we see a share called all-data

NOTE: we use -N which means use “no password”, in otherwords a blank password. Otherwise without -N it would ask for a password and we would hit enter to simulate no password. This passwordless entry only works for guest mode / anonymous access. If you do need username / password access you would not use -N. Instead you would use -U to specify the user (or username & domain at the same time DOMAIN\USER or USER@DOMAIN.com). In this case I have a very simply samba config that allows anonymous access so I use -N.

Then test listing the contents of the share with ls

smbclient //10.39.2.11/all-data -c "ls" -N
# Unknown parameter encountered: "force writeback"
# Ignoring unknown parameter "force writeback"
# WARNING: The "null passwords" option is deprecated
# Unknown parameter encountered: "reverse sendfile"
# Ignoring unknown parameter "reverse sendfile"
# Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.0.5]
#   .                                   D        0  Tue Aug 27 10:21:11 2013
#   ..                                  D        0  Mon Oct 19 18:57:36 2015
#   aquota.group.new                    N     7168  Tue Aug 27 10:21:11 2013
#   backup                              D        0  Wed Jul 22 14:21:10 2015
#   .timemachine                       DH        0  Mon Aug 17 14:09:03 2009
#  lost+found                          D        0  Mon Aug 17 14:06:03 2009
#  aquota.group                        N     7168  Mon Dec  1 17:58:38 2014
#  aquota.user.new                     N     8192  Tue Aug 27 10:21:11 2013
#  home                                D        0  Fri Nov 22 10:07:23 2013
#  aquota.user                         N     8192  Mon Dec  1 17:58:38 2014
#  archive                             D        0  Wed Apr 15 15:52:28 2015
#
#                65535 blocks of size 33553920. 7371 blocks available

Try listing contents of a folder in a share:

smbclient //10.39.2.11/all-data -c "ls archive/*" -N
# Unknown parameter encountered: "force writeback"
# Ignoring unknown parameter "force writeback"
# WARNING: The "null passwords" option is deprecated
# Unknown parameter encountered: "reverse sendfile"
# Ignoring unknown parameter "reverse sendfile"
# Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.0.5]
#   .                                   D        0  Wed Apr 15 15:52:28 2015
#   ..                                  D        0  Tue Aug 27 10:21:11 2013
#   2882009CDrive                       D        0  Tue Sep  1 19:12:00 2009
#   SQLServer2005SP3.exe                A 341786976  Thu Nov 27 07:28:00 2008
#   someapp1.exe                        A  4487016  Mon Aug 24 13:12:12 2009
#   Futura Font                         D        0  Wed Dec 24 11:37:35 2014
# 
#                 65535 blocks of size 33553920. 7371 blocks available

NOTE: to list the insides of a directory you have to suffix with /*

Now test getting the permission of a file or a folder

smbclient //10.39.2.11/all-data -c "getfacl archive" -N
# # file: \archive
# # owner: 65534
# # group: 65534
# user::rwx
# group::rwx
# other::rwx
# default:user::rwx
# default:group::rwx
# default:other::rwx

NOTE: I ommited that warning/error prefix message on this output, and the next output as well

Now testĀ getting/downloading a file

smbclient //10.39.2.11/all-data -c "get archive/someapp1.exe /root/someapp2.exe" -N
# getting file \archive/cp010883.exe of size 4487016 as /root/cp010883.exe (625970.1 KiloBytes/sec) (average 625978.8 KiloBytes/sec)

NOTE: notice I downloaded a file call someapp1 from folder archive in the share all-data off the samba server 10.39.2.11, to a /root folder locally on this machine (where im running the smbclient command). I called the file someapp2.exe. This even lists the speed of download.

The End

Leave a Reply

Your email address will not be published. Required fields are marked *