Categories: Ubuntu

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.

Sponsored

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

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

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

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

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.

Sponsored

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

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

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:

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

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.

Ubuntu Server Admin

Recent Posts

Ubuntu vs Debian: Linux Distributions Compared Deep Dive

Debian and Ubuntu are two popular Linux distributions. In this deep dive we will guide…

8 hours ago

How to Install Google Cloud BigQuery Python client library on Linux

In this article, we will see how to Install Google Cloud BigQuery Python client library…

2 days ago

Wallpaper Contest for Xfce 4.20 open for voting

Nov 15,2024 Wallpaper Contest for Xfce 4.20 open for voting The submission phase for the…

2 days ago

Canonical announces the first MicroCloud LTS release

MicroCloud 2.1.0 LTS is now available, expanding the number of Canonical infrastructure solutions with a…

3 days ago

Join Canonical in Paris at Dell Technologies Forum

Canonical is thrilled to be joining forces with Dell Technologies at the upcoming Dell Technologies…

4 days ago

Bringing automation to open source 5G software at Ubuntu Summit 2024

In today’s massive private mobile network (PMN) market, one of the most common approaches to…

5 days ago