In this blog post, we are going to take a look at how to mount SMB shares on Linux. From the related terms, to what needs to be installed, and how to mount it to your local file system. Then wrapping up with troubleshooting and unmounting.
What Is CIFS?
CIFS stands for common internet file system, it’s a dialect of the SMB protocol.
What Is SMB?
SMB or server message block is a protocol used to share files, printers, and more. Most think of Microsoft created SMB because of its use in Windows, but it was created by Barry Feigenbaum at IBM. The way it was built allows for protocol extensions. Microsoft has written the most extensions to the protocol.
Why SMB?
Popularity, most operating systems including Windows, macOS, Linux, and Unix support the SMB protocol.
Install CIFS Utilities Packages On Linux
Although we will be connecting using SMB the package name for the user space tools for SMB is called cifs-utils. This is a package created by the samba.org team who you might be surprised to know has been working with SMB before Microsoft implemented it in Windows NT.
To install on Debian/Ubuntu
sudo apt install cifs-utils
To install on RPM systems using DNF
sudo dnf install cifs-utils
What SMB Version Should I Use?
It’s recommended to use the latest version supported by the server and client.
Assuming you are running modern operating systems, you are likely to at least have support for SMB 3.0. You may need to refer to documentation or the internet to confirm what SMB versions are supported.
The supported version of SMB on Linux will depend on your Linux kernel version, for SMB3 kernel 3.12+ is needed (or a backport of cifs.ko at or above version 2.02).
Create A Directory To Mount The Share
Before we can get started you will need to need an empty directory that you will mount the share to this is represented as /path/to/mount/point below.
If you need to create this here is an example command.
sudo mkdir /mnt/smb-share
Feel free to change the path for your needs.
Mounting From The Command Line
To mount from the command line this is what the syntax of the command will look like.
sudo mount -t cifs -o vers=X,username=user //[IP/hostname]/path/to/share /path/to/mount/point
- First, replace X with the version of SMB you want to use, see the options listed below:
- 1
- 2.0
- 2.1
- 3.0
- 3.11 (Version 3.1.1)
- Then replace the user with the correct username.
- Replace [IP/hostname] with the IP or hostname of the system you want to connect to using SMB.
- Replace the /path/to/share, this is the path to the share on the SMB server.
- Finally, replace /path/to/mount/point with a path to a blank folder (you may need to create this folder using mkdir) to which the share can be mounted.
After running the command you will be prompted for the password.
Auto Mounting
If you would like to mount the share on boot, you will need to add a line to /etc/fstab.
Be aware that regular users may have permission to view this file so you don’t want to have login credentials in this file. Instead, you will want to create a credentials file as shown below.
Creating the credentials file
I recommend creating the file with a unique name in case you need to mount more than one share.
sudo nano /etc/SMB-credentials-[unique-identifier]
Add this to the file
username=
password=
Append the username and password before saving and exiting out of nano (or your text editor of choice).
Now this is what you will need to add to /etc/fstab.
//[IP/hostname]/path/to/share /path/to/mount/point cifs credentials=/etc/SMB-credentials-[unique-identifier],vers=X 0 0
- First, replace X with the version of SMB you want to use. This will be one of the options below
- 1
- 2.0
- 2.1
- 3.0
- 3.11 (Version 3.1.1)
- Replace [IP/hostname] with the IP or hostname of the system you want to connect to using SMB.
- Replace the /path/to/share this is the path to the share on the SMB server.
- Finally, replace /path/to/mount/point with a path to a blank folder () to which the share can be mounted.
To test mounting use mount -a to confirm if it will mount.
Troubleshooting
If you’re running into issues check the following:
- Check the IP, username, password, SMB version, and paths.
- Can you reach the server from the client?
- Are there any firewalls in the way (this includes hardware and software firewalls)?
- Use journalctl -kr if you get an error code to see the full message.
How To Unmount The Share
- To unmount the share temporally use:
umount [mount_point]
- To unmount permanently (even after rebooting) remove from /etc/fstab and then use the umount command above.
Note: If you run into issues unmounting remove from /etc/fstab and restart instead.
Conclusion
In this blog post, we have resolved the misconception that CIFS are different from. From there we discussed the related terms, to what needs to be installed, and how to mount it to your local file system. Wrapping up with troubleshooting and unmounting.
Embracing a lifelong passion for technology since childhood, CJ delved into the intricate workings of systems, captivated by the desire to understand the unknown. This innate curiosity led to his discovery of Linux, a revelation that resonated deeply. With more than 7 years of on the job experience, he’s honed his technical skills as a Geek and Senior Linux Systems Administrator.
Leave a Reply