How to Mount Samba Share in Ubuntu Linux

In this tutorial we are going to learn how to mount samba share on Ubuntu.

For this tutorial I am using Ubuntu Server 16.04, But you can use the following guide to mount Samba CIFS Share in any version of Ubuntu Linux including Ubuntu Desktop.

Install cifs-utils package in Ubuntu

In order to mount Samba share on Ubuntu we need to install the cifs-utils package.

apt-get update
apt-get install cifs-utils

The cifs-utils package provides the tools and utilities that need to mount samba share on Ubuntu Linux.

Mount Samba Share using the Mount Command

After installing cifs-utils package, we can use mount command to mount samba share instantly.

mount -t cifs -o username=username //server-name/sharename /mountpoint

Once you execute the Command you will prompt for the Samba password of the samba user.

  • The Server name can be the domain name or the IP Address of the Samba Server.
  • It is also possible to provide the password with the mount command.
mount -t cifs -o username=username,password=password //server-name/sharename /mountpoint

Example

mount -t cifs -o username=smbuser //192.168.1.100/documents /mnt

As per the above example, I used the mount command to mount samba share called documents from the Server 192.168.1.100. The mount point is /mnt and samba user is smbuser.

How to Mount Samba Share in Ubuntu Linux
mount -t cifs -o username=smbuser,password=smbpass //192.168.1.100/documents /mnt

This time we also provided the password for the smbuser as a command option.

Add Samba Share to /etc/fstab

To mount samba share automatically when system reboot, We need to add an entry to the /etc/fstab file.

//192.168.1.100/documents /mnt cifs username=smbuser,password=abc123@# 0 0

When system reboot, Ubuntu will mount the samba share specified in the /etc/fstab file.

To check the fstab file without reboot, use the mount -a command.

mount -a

The mount -a command will Mount all filesystems mentioned in the fstab file.

Authenticate Samba Share using Credential File

We can use a credentials file that contains a username and password to authenticate the samba User.

Example

First, we need to create the credentials file.

vim /var/credentials

Next we need to add the username and password to the credentials file as follows.

username=username
password=password

Then we can use the credentials file to mount Samba Share on Ubuntu Server.

Mount using the mount Command

mount -t cifs -o credentials=/var/credentials //192.168.1.100/documents /mnt

The fstab entry should be as follows.

//192.168.1.100/documents /mnt cifs credentials=/var/credentials 0 0

So that is how we can mount samba share on Ubuntu Linux using the CIFS Protocol.