How do I mount SMB shares in Ubuntu?

SMB is a client-server file exchange protocol, which stands for Server Message Block, which was invented by IBM in 1984 with the aim of giving computers read or write access to files on a remote host using a LAN (Local Area Network). The SMB protocol, which makes files or directories accessible from a remote host, is called a shared resource. This means that we can mount a shared file or directory on our system using the local network.

SMB was formerly known as CIFS and is an old version or dialect of SMB, which stands for Common Internet File System, which was created by Microsoft and is a specific implementation of the Server Message Block protocol.

In this article, we’ll walk you through each small step of connecting SMB shares in Ubuntu using a Samba file server. Samba uses the SMB protocol and performs the same function as SMB, that is, it allows files to be shared on local networks with other systems. But before moving on, let me highlight the point that this article assumes that you have already shared a directory on the remote system, and that you will be able to access that directory in this article.

Step 1. Updating and updating the apt-cache repository

The first step is to update our apt packages using the update command in our Ubuntu 20.04 terminal:

                      $ sudo apt update

All of our packages are up to date, however, if our packages are not up to date, we must run the following command to upgrade:

                      $ sudo apt upgrade

Step 2: Installing the Cifs-utils package

Run the below command to install cifs-utils package on Ubuntu system:

                      $ sudo apt install cifs-utils

Step 3: Create Directory

Let’s now create a directory where we will mount the shared drive:

                      $ sudo mkdir /media/share

Step 4: Create a credential file

This step involves creating a credential file in our home directory using. (Period) which is necessary for security reasons, which will make our file hidden. To do this, run the following command, which will open the file in the nano editor:

                      $ sudo nano /root/.examplecredentials

You can replace the filename with whatever you want:

Now that the file is open, enter the following two lines in the file, which will be our username and samba password:


You can replace the username and password with your desired username and password and then press CTRL + S to save the file and CTRL + X to exit the file.

We will then make the /root/.examplecredentials file read-only and root-only, so we will restrict all non-root accounts by running the following command in our Ubuntu 20.04 terminal:

                      $ sudo chmod 400 /root/.examplecredentials

Step 5: Mount the remote samba

In this step, we will run the command that will mount the remote samba share on our Ubuntu system:

                      $ sudo mount -t cifs -o rw,vers=3.0,credentials=/root/.examplecredentials // /media/share

Replace the IP address in the above command where you have already shared a directory or folder on the remote system and if it is an Ubuntu system you can find the IP address using the ip a command:

                      $ ip a

The IP address of the remote Ubuntu system from which the sharedDir was shared is “” which was specified in the above mount command.

Step 6. Automatic connection upon system reboot.

The filesystem that was manually mounted in the previous step will not be mounted after we reboot our Ubuntu / system, so to fix this problem, we will first open the / etc / fstab file in nano editor and then add some configuration to that file. To open the / etc / fstab file in the nano editor, run the following command:

                      $ sudo nano /etc/fstab

The above command will open the / etc / fstab file.

Now add the following line to the file opened in nano editor:

                      // /media/share cifs vers=3.0,credentials=/.examplecredentials

Remember that you need to replace the IP address with your IP address, then press CTRL + S to save the above file, and then press CTRL + X to close the file.


SMB is a file exchange protocol designed to allow computers to access files from remote systems over a LAN, while CIFS is a special dialect of SMB that has much the same functionality.

In this article, we showed you how to mount an SMB share on Ubuntu 20.04 using the samba file server; however, the commands used were generic and could be used in any Linux distribution.

Related Posts