Mount SMB Shares on Ubuntu

How to Mount SMB Shares on Ubuntu 22

Finding a method on how to mount SMB shares on Ubuntu can help users with transferring the files over the same LAN. Let’s see how it is done.

SMB or Server Message Block is a well-known protocol used in the client-server model to transfer files. In addition, it is also useful for sharing files among the machines connected to the same LAN. Originally developed by IBM, SMB is developed to provide authenticated access to printers and files to the nodes in the same network.

Also known as the Response-Request Protocol, SMB operates at the Application Layer and relies on TCP/IP port 445 to communicate over the network. The SMB protocol works in the following way: the client sends the SMB request to the server to initiate the connection. In return, the SMB server sends a response to accept the connection request and establish a two-way communication channel.

In this article, you will cover how to set up SMB protocol on Ubuntu, along with its various sharing mechanisms.


For this tutorial, you will need a root account or a machine with the sudo privilege. However, there is no need for configured mount directory or credential setting at this stage.


The basic mount command syntax looks something like this:

mount [-l | -v | -h ]
sudo mount [ -fnrsvw ] [-t fstype] [-o options] <device name> <directory name>

Mount Options in the Mount Command

Here are a few options that you can use with the mount command:

  • –l: Enables users to add labels on mount output
  • -h: Displays all other options for the mount command
  • -V: Shows the current mount version
  • -a: Automatically mounts all filesystems indicated in /etc/fstab
  • -t: Sets the filesystem type of the mounted device
  • -T: Gets info on alternative fstab if available
  • -O: Used to limit the set of filesystems  
  • -r: Read-only

For a detailed guide, check out its manual page. Alternatively, you can access the manual from the terminal as well. For this step, use the command:

man mount

Mount SMB Shares on Ubuntu

Update the System

To get started with the mounting, the first step is to update the system. Head over to the command prompt by pressing “Ctrl + Alt+ T”. Execute the following command to update all the existing utilities and dependencies:

sudo apt-get update && sudo apt upgrade

You should get a similar output:

mount smb shares on ubuntu

Next, use the install command to install the required CIFS utilities. Common Internet File Systems (CIFS) is an open-source file and printer sharing protocol. It is designed to provide unauthenticated sharing access to nodes over the same network. To install CIFS, execute the command given below:

sudo apt install cifs-utils -y

The output should look something like this:

mount smb shares on ubuntu

Setup SMB Protocol

After that, create a directory where you will place all the files and folders you wish to share. In other words, the content should be accessible by other machines in the same network. For this step, use the mkdir command. Make sure to replace the path with your desired path name. 

For instance, type:

sudo mkdir <path>

For example:

sudo mkdir /mnt/local_share

After that, create a secured credential file using the text editor of your choice. To create a secured file, simply place “.” before the file name. Specifically, type:

sudo nano /root/.examplecredentials

Alternatively, you can use the vim editor. For instance, execute the command as shown below:

sudo vim /root/.examplecredentials

Copy the following contents in your newly created file:


Save the file and exit the editor. 

Configure the access permissions of this secured file. For this step, use the chmod command. For example:

sudo chmod 400 /root/.examplecredentials

Lastly, determine the IP Address of the machine for the mounted share using the ip command. Specifically, type:

ip a


Find ip address

Mount SMB Shares on Ubuntu

To successfully mount the share, execute the mount command as shown below:

sudo mount -t cifs -o rw,vers=3.0,credentials=/root/.examplecredentials // /media/share
sudo mount -t cifs //<vpsa_ip_address>/<export_share> /mnt/<local_share>

The syntax of the current command is:

sudo mount [file system type] cifs -o [file permissions] [version] [path to the credential files] [IP address of the host] [path to the mounted directory]

Make sure to replace the IP Address with the IP Address of your machine. This will automatically mount the shared directory along with the credential settings. 

Alternatively, you can also mount SMB shares manually by configuring the /etc/fstab file. Open this file using the text editor of your choice. For example:

sudo nano /etc/fstab


mount shares manually

Next, add the following details at the end of the file:

  • Your machine’s IP address
  • Shared mount path
  • Path to the credential file

Specifically, type:

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

Make sure to write your machine’s IP Address. Next, add the following lines of information in the same file:

//WIN_SHARE_IPaddress/$shared_name /mnt/winshare cifs credentials=/etc/cifs-credentials,file_mode=0755,dir_node=0755 0 0

Save the changes and exit the text editor. Lastly, run the mount command on the terminal to share the mounted directory with other users on the same network. For instance, type:

sudo mount -a

Unmount SMB Shares on Ubuntu

If you no longer wish to use the mounted directory or keep it available for users, you can simply unmount it using the unmount command. For example:

sudo umount <path to the mounted directory>

Specifically, type:

sudo umount /mnt/winshare

By now, you have an excellent understanding of how to mount SMB shares on Ubuntu. With the help of CIFS utilities, you can easily use SMB shares on Ubuntu to communicate with other uses on the same LAN. For more information on the mount command, check its official documentation.

Also, don’t forget to go through a basic guide on mount command and use SAMBA for SMB shares for seamless file transfer and flawless performance. We hope the article was useful to you.

If this guide helped you, please share it.

Leave a Reply
Previous Article
HAProxy Logo

How to Setup HAProxy on Ubuntu 22

Next Article
How to Send Multiple Sed Replacements on Linux

How to Send Multiple Sed Replacements on Linux

Related Posts