# Accessing An SMB Share With Linux Machines

Server Message Block (SMB) is a network resource sharking protocol based on a client-server model. While Microsoft authors the most popular Microsoft SMB protocols and Microsoft operating systems are the most common SMB servers, it is possible for Linux machines to access an SMB share. Here, we’ll take a closer look at what an SMB share is, Linux tools for accessing SMB shares, and provide an example of how to access an SMB share from a Linux machine.

#### What Is An SMB File Share?

An SMB file share is a shared resource clients can access on a server.

An SMB file share is most often a directory, but an SMB share can also be other resources such as a specific shared file or a printer. Sometimes, you may see the term CIFS share used interchangeably with SMB share. This is because Common Internet File System (CIFS) is often directly associated with SMB version 1 (SMBv1).

• ℹ️ Note: For more information on the technical differences between SMBv1/CIFS, SMBv2, and SMBv3, we recommend reading SMB Most Important Features. For the purpose of this article, just note that SMBv1 is insecure and inefficient and shouldn’t be used today. Generally, if you use SMB you’ll want to use SMBv3.0, SMBv3.02, or SMB v3.1.1 if your servers and clients support it.

SMB clients access SMB servers to gain access to the resources provided as SMB shares. A SMB server/client connection can be something as simple as two Windows 10 PCs sharing resources. Alternatively, it can be something more complex like using SMBv3 to work with clustered shared volumes and storage for virtual machines in a HyperV cluster.

#### Linux Tools For SMB File Shares

cifs-utils and smbclient are two popular examples of Linux tools that can be used with SMB shares.

There are a variety of graphical tools for Linux desktop users that can act as an SMB client. For example, Konqueror a web browser and file management tool for KDE desktops supports SMB. So does the popular SMB4K utility.

However, in this section, we’ll look at two lower-level tools that can provide extensibility and options for environments without a graphical user interface (GUI).

#### Where Samba Fits In

If you’ve done some prior research, you likely know working with SMB on Linux systems often involves Samba. But what is Samba and how does it fit in here? Samba is a software suite that enables file and print services on Linux operating systems. Many Linux SMB tools — including the two we’ll mention below — are (or were) directly part of the Samba suite.

cifs-utils for mounting SMB File shares on Linux

cifs-utils is a suite of tools used to mount SMB shares on Linux machines. This suite of tools used to be part of the Samba suite, but can now be installed independent of the Samba suite. cifs-utils is available in the repositories for many popular flavors of Linux including Ubuntu, Debian, CentOS, Fedora, OpenSUSE, and Arch Linux.

If it’s not already installed, you can usually install cifs-utils with your operating system’s package manager. For example, on Ubuntu, something like:

$sudo apt-get install cifs-utils Or on CentOS something to the effect of:$ sudo yum install -y cifs-utils

smbclient acts as an ftp-like client for SMB file share access

smbclient is a part of the Samba suite of tools. With smbclient you get an interactive client that enables you to do things like list files in remote directories (ls), download (get) files, upload (put) files, and delete files (rm). If you’ve ever used command-line FTP clients, smbclient will likely feel very similar.

#### How to access an SMB File Share with Linux Machines

Here are some specific examples of how to use Linux to mount or access an SMB share.

Now that we’ve reviewed what smbclient and cifs-utils are, let’s take a look at some basic commands you can use to access an SMB share on the same network as your Linux machine. Note that SMB versions, configurations, file access permissions, encryption, and authentication methods can all impact how these samples work in your environment.

Using cifs-utils to mount Mounting an SMB share on a Linux machine

Once you have cifs-utils installed, you can mount an SMB share from a Windows machine to your Linux machine following a process like this:

Create a directory where you will mount the share, here we’ll create a directory at “/mnt/stovetop”
$sudo mkdir /mnt/stovetop Authenticate to the Windows share and mount it at the directory created in the previous step. In basic cases, you can do this with the command$ sudo mount -t cifs -o username= ///<path/to/share>

Here, we’ll authenticate as a user named “johnny” and use the SMB share on at “\\WindowsKitchen\pepperneggs” which has two files “eggs.txt” and “peppers.txt” in it.
$sudo mount -t cifs -o username=johnny //WindowsKitchen/pepperneggs /mnt/stovetop Password for johnny@//WindowsKitchen/pepperneggs:$
Now we can see the files on our Linux machine!
$ls /mnt/stovetop/ eggs.txt peppers.txt$
Using smbclient to access an SMB share from a Linux machine
Now, suppose we want to simply access the same share and interactively view the contents of \\WindowsKitchen\pepperneggs from our Linux machine.

Generally, the command to do this is:
$smbclient -U \\\\\\<path\\to\\share> Note that we need to use the extra backslash characters to escape the backslash characters in the Linux bash shell. Let’s look at a specific example using the same “\\WindowsKitchen\pepperneggs” SMB file share. First, we’ll connect to the share:$ smbclient -U david \\\\WindowsKitchen\\pepperneggs
Try “help” to get a list of possible commands.
smb: \>

Now, let’s list the files we can see at the “smb: \>” prompt:
smb: \> ls
. D 0 Sun Feb 7 15:16:13 2021
.. D 0 Sun Feb 7 15:16:13 2021
eggs.txt A 41 Sun Feb 7 15:16:34 2021
peppers.txt A 14 Sun Feb 7 15:16:04 2021

243863551 blocks of size 4096. 202309870 blocks available
smb: \>

Finally, let’s download “eggs.txt” and exit back to our local Linux prompt.
smb: \> get eggs.txt
getting file \eggs.txt of size 41 as eggs.txt (1.1 KiloBytes/sec) (average 1.1 KiloBytes/sec)
smb: \> exit
$ls eggs.txt$

Success! We’ve downloaded the file from our Windows SMB file share to our Linux machine!

Using curl to access a legacy SMBv1 file share

You may have heard curl — the popular Linux tool for all sorts of file transfers and network connections — supports SMB. This is true to an extent, but unfortunately it is only SMBv1. An generic command to download a file using curl and SMBv1 is:

$curl -u “” smb:///<path/to/shared/file> -o <path/to/local/file> Since SMBv1 is usually disabled on production systems, you’re likely to see an error like this if you try:$ curl -u “johnny” smb://WindowsKitchen/pepperneggs/eggs.txt -o eggs.txt
Enter host password for user ‘johnny’:
$On an SMB file share with SMBv1 enabled (which we do NOT recommend!) the same command will succeed.$ curl -u “johnny” smb://WindowsKitchen/pepperneggs/eggs.txt -o eggs.txt
Enter host password for user ‘johnny’:
% Total % Received % Xferd Average Speed Time Time Time Current
$ls eggs.txt$