How to Mount an SMB Share in Linux
The Server Message Block (SMB) protocol facilitates network file sharing, allowing applications to read and write to files and request services from server programs. This protocol is pivotal for seamless communication between different devices in a network, particularly in mixed OS environments like Windows and Linux.
Users can access files on a Windows server or any SMB-enabled device straight from their Linux workstation by mounting an SMB share. In order to ensure seamless file sharing and network connectivity, this tutorial will walk you through the process of mounting an SMB share on Linux.

Linux terminal is important tool to install SMB Share in Linux
And if you’re looking for a reliable, high-performance, and budget-friendly solution for your workflows, Hostman has you covered with Linux VPS Hosting options, including Debian VPS, Ubuntu VPS, and VPS CentOS.
Prerequisites for Mounting SMB Shares Copy link
Before mounting an SMB share, ensure the following prerequisites are met:
-
A Linux system, such as a Hostman cheap cloud server, with
rootorsudoprivileges. -
The
cifs-utilspackage installed on your Linux system. -
Access credentials (username and password) for the SMB share.
-
Network connectivity between your Linux system and the SMB server.
Installing Necessary Packages Copy link
The cifs-utils package is essential for mounting SMB shares on Linux. Additionally, the psmisc package provides the fuser command, which helps manage and monitor file usage.
Update Package List and Upgrade System
First, update your package list and upgrade your system:
sudo apt updateInstall cifs-utils and psmisc
Install the necessary packages:
sudo apt install cifs-utils psmiscVerify Installation
Verify the installation of cifs-utils and availability of the fuser command:
mount -t cifs
fuserFinding SMB Share Details Copy link
Get the SMB share information, such as the share name and the server name or IP address. You may need to examine the server setup or speak with your network administrator.
Example:
- Server:
smbserver.example.com - Share:
sharedfolder
Mounting SMB Shares Using the mount Command Copy link
To mount the SMB share, use the mount command with the -t cifs option, specifying the SMB protocol.
Create a directory to serve as the mount point:
sudo mkdir /mnt/smb_shareMount the SMB share using the following command:
sudo mount -t cifs -o username=your_username,password=your_password //192.0.2.17/SharedFiles /mnt/smb_shareReplace your_username and your_password with your actual username and password. Ensure /mnt/smb_share is an existing directory.
Verifying the Mount
To confirm that the SMB share is successfully mounted, use the mount command:
mount -t cifsNavigate to the mount point and list the files:
cd /mnt/smb_share
lsCreating a Credentials File
Make a credentials file so you don't have to enter your credentials every time. This file has to be guarded and hidden.
Use a text editor to create the file:
nano ~/.smbcredentialsAdd the following content, replacing with your actual credentials:
username=your_username
password=your_passwordSet appropriate permissions for the file:
sudo chown your_username: ~/.smbcredentials
sudo chmod 600 ~/.smbcredentialsMount Using the Credentials File
Mount the SMB share using the credentials file:
sudo mount -t cifs -o credentials=~/.smbcredentials //192.168.2.12/SharedFiles /mnt/smb_share Copy link
Quick example of how SMB Shared is mounted in Linux terminal
Automating SMB Share Mounts Copy link
To automate the mounting process, add an entry to the /etc/fstab file. This will ensure the SMB share is mounted at boot.
1. Open /etc/fstab for editing:
sudo nano /etc/fstab2. Add the following line:
//smbserver.example.com/sharedfolder /mnt/smbshare cifs username=johndoe,password=securepassword,iocharset=utf8,sec=ntlm 0 03. Save and close the file.
4. Test the fstab entry:
sudo mount -aEnsure no errors are displayed.
Troubleshooting Common Issues Copy link
Permission Denied
Check your credentials and permissions on the SMB server.
No Such File or Directory
Ensure the server IP, share path, and mount point are correct.
Mount Error 13 = Permission Denied
Double-check your username and password.
Mount Error 112 = Host is Down
Verify network connectivity and server availability.
Unmounting an SMB Share Copy link
To unmount the SMB share, use the umount command followed by the mount point:
sudo umount /mnt/smb_shareConclusion Copy link
Mounting an SMB share in Linux is a straightforward process that enhances file sharing capabilities across different operating systems. By following this tutorial, you can efficiently set up and troubleshoot SMB share mounts, facilitating seamless network communication and file access.
Don't forget to check how to configure server image on Lunix!
Frequently Asked Questions (FAQ) Copy link
How do I mount an SMB share in Linux manually? Copy link
Use the mount command with the cifs type. The syntax is: sudo mount -t cifs -o username=[user] //server/share /mnt/local_mountpoint You will be prompted to enter the password for the SMB user.
How do I mount a Samba share in Linux permanently? Copy link
To mount a share automatically at boot, add an entry to your /etc/fstab file. It generally looks like this: //server/share /mnt/point cifs username=user,password=pass 0 0
Note: For security, it is better to use a credentials file instead of putting the password directly in fstab.
How do I mount an SMB share in CentOS/RHEL? Copy link
First, ensure the necessary utilities are installed by running sudo dnf install cifs-utils. Once installed, the mount process is the same as other distributions:
sudo mount -t cifs -o username=[user] //server/share /mnt/point
What do I do if I get a "wrong fs type" error? Copy link
This usually means the helper utilities are missing. On Ubuntu/Debian, run sudo apt install cifs-utils. On CentOS/Fedora, run sudo dnf install cifs-utils.
How do I unmount the share when I'm done? Copy link
Use the umount command followed by the local directory: sudo umount /mnt/local_mountpoint