How to Mount SMB Shares on Ubuntu? 2

How to Mount SMB Shares on Ubuntu?

SMB is a client-server, file-sharing protocol that stands for Server Message Block which was invented by IBM in 1984 for the purpose of allowing computers to access files for reading or writing on a remote host using the LAN (Local area network). The SMB protocol that makes available the files or directories that are accessed on the remote host are called shares. This means that we can mount a shared file or directory to our system using the local area network.

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

In this article, we will provide you with each and every little step on how to mount SMB shares on Ubuntu using the Samba file server. Samba uses the SMB protocol and has the same function as SMB i-e enabling file sharing on Local area networks with other systems. But before going forward let me highlight a point that this article assumes that you have already shared a directory on a remote system and you will access that directory in this article.

Step1: Updating and upgrading apt-cache repository

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

$ sudo apt update

How to Mount SMB Shares on Ubuntu? 3

All our packages are up to date however if our packages are not up to date then we have to run the following command to upgrade:

$ sudo apt upgrade

How to Mount SMB Shares on Ubuntu? 4

Step2: Cifs-utils Package installation

Execute the command that is given below to install the cifs-utils package on Ubuntu system:

$ sudo apt install cifs-utils

How to Mount SMB Shares on Ubuntu? 5

How to Mount SMB Shares on Ubuntu? 6

Step3: Creating Directory

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

$ sudo mkdir /media/share

Step4: Creating Credentials file

This step involves creating the credentials file in our home directory and with the use of .(dot) which is needed for security reasons that will make our file hidden. For this purpose execute the below command which will open the file in the nano editor:

$ sudo nano /root/.examplecredentials

How to Mount SMB Shares on Ubuntu? 7

You can replace the name of the file with whatever you want the file name to be:

Now that the file is opened type the following two lines in the file which will be our samba username and password:

username=example_username
password=example_password

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

Next, we will make the /root/.examplecredentials file readable only and only for the root account hence will put restriction on all non-root accounts by executing the following command in our Ubuntu 20.04 terminal:

$ sudo chmod 400 /root/.examplecredentials

How to Mount SMB Shares on Ubuntu? 8

Step5: Mount samba share

In this step we will execute the command which will mount the remote samba shared directory on our Ubuntu system:

$ sudo mount -t cifs -o rw,vers=3.0,credentials=/root/.examplecredentials //192.168.18.112/sharedDir /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 that is Ubuntu system then you can find the IP address with ip a command:

$ ip a

How to Mount SMB Shares on Ubuntu? 9

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

Step6: Automount on system reboot

The manually mounted file system in the above step will not be mounted once our Ubuntu/system reboots, hence to solve this problem first we will 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 execute the following command:

$ sudo nano /etc/fstab

The above command will open /etc/fstab file and you will see something like shown below on your system screen:

How to Mount SMB Shares on Ubuntu? 10

Now add the following line in the file that was opened with the nano editor:

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

How to Mount SMB Shares on Ubuntu? 11

Remember that you have to replace the IP Address with your IP Address after which press CTRL+S to save the above file and then press CTRL+X to close the file.

Conclusion

SMB is a file-sharing protocol created for the purpose of allowing computers to access remote systems files over a LAN network and CIFS is a particular dialect of SMB having almost the same functionality.

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

Leave a Comment

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