How to linux mount samba share

Samba is a software suite that allows you to share files and printers between different operating systems, such as Linux and Windows. It uses the SMB/CIFS protocol to enable network sharing. In this guide, we’ll walk through how to mount a Samba share on a Linux machine, allowing you to access shared resources from a remote server or another computer on the network.

What is Samba?

Samba is a free software re-implementation of the SMB (Server Message Block) protocol, which allows file and printer sharing between computers over a network. It enables Linux and UNIX systems to access shared resources like files and printers from Windows systems and vice versa.

In this blog, we will show you how to mount a Samba share on Linux so that you can easily access and use files stored on a remote system over the network.

Prerequisites for Mounting a Samba Share

Before proceeding with mounting a Samba share, ensure the following:

  • Your Linux machine is connected to the network where the Samba share is located.
  • You have the IP address or hostname of the server hosting the Samba share.
  • You know the name of the shared folder or drive that you want to mount.
  • You have the appropriate credentials (username and password) for accessing the Samba share.
  • The necessary Samba client software is installed on your Linux machine.

Installing Samba Client on Linux

If you don’t already have the Samba client tools installed on your system, you can install them using your package manager.

On Ubuntu/Debian-based systems:

sudo apt-get install cifs-utils

On Red Hat/CentOS/Fedora-based systems:

sudo yum install cifs-utils

On Arch Linux:

sudo pacman -S cifs-utils

Once the package is installed, you’re ready to mount the Samba share on your system.

Mounting a Samba Share in Linux

To mount a Samba share, you can use the mount command with the CIFS protocol. Here’s the general syntax:

sudo mount -t cifs //server-ip-address/share-name /mnt/your-mount-point -o username=your-username,password=your-password

Let’s break this down:

  • //server-ip-address/share-name: This is the network path to the Samba share. Replace server-ip-address with the IP address or hostname of the server and share-name with the name of the shared folder.
  • /mnt/your-mount-point: This is the local directory where you want to mount the share. If the directory does not exist, you will need to create it first.
  • username=your-username,password=your-password: Replace your-username and your-password with your Samba credentials for the share.

Example Command:

sudo mount -t cifs //192.168.1.100/shared_folder /mnt/shared -o username=john,password=mypassword

This command mounts the Samba share located at //192.168.1.100/shared_folder to the local directory /mnt/shared using the credentials for the user john.

Creating the Mount Point Directory

Before you can mount the Samba share, you need to create a directory where the share will be mounted. For example, if you want to mount the share at /mnt/shared, you can create this directory with the following command:

sudo mkdir /mnt/shared

If the directory already exists, you can skip this step.

Mounting with Additional Options

In some cases, you may need to specify additional options when mounting the Samba share. For example:

1. Mounting a Share as Read-Only

If you want to mount the share as read-only, add the ro option:

sudo mount -t cifs //192.168.1.100/shared_folder /mnt/shared -o username=john,password=mypassword,ro

2. Mounting a Share with Domain

If the Samba share is part of a Windows domain, you can specify the domain using the domain option:

sudo mount -t cifs //192.168.1.100/shared_folder /mnt/shared -o username=john,password=mypassword,domain=MYDOMAIN

3. Using Kerberos Authentication

If you’re using Kerberos authentication, you can mount the share without supplying a password by using the krb5 option:

sudo mount -t cifs //192.168.1.100/shared_folder /mnt/shared -o sec=krb5

Unmounting the Samba Share

Once you no longer need the Samba share, you can unmount it using the umount command:

sudo umount /mnt/shared

This will safely disconnect the Samba share from your Linux system. Make sure no files are open or in use from the mounted share before unmounting it.

Conclusion

Mounting a Samba share in Linux is a straightforward process, provided you have the necessary permissions and information about the share. Whether you’re accessing files from a Windows server or another Linux machine, the mount command with the CIFS protocol offers a simple and efficient way to connect to remote shared folders. By following the steps outlined in this guide, you can easily mount and access Samba shares on your Linux system.