Samba is the standard Windows interoperability suite of programs for the Unix and Linux operating systems. Samba server uses SMB/CIFS protocol for the secure, stable and file/printer sharing.
This tutorial will help you to mount remote samba share to your Linux system.
Mounting Samba Share on Unix and Linux
Follow the step by step guide for the mounting of remote samba share on Ubuntu and Debian system. Also enables to auto mount shared drive even after system reboot.
- Step 1 – You need to install package cifs-utils on your system. Run the following command on the terminal for the installation.
sudo apt install cifs-utils
- Step 2 – After that create a directory to mount the share drive.
sudo mkdir /media/share
- Step 3 – Now create a credentials file to your system. Make this as a hidden file using dot (.) for security purpose. It’s good to create it in your home directory.
nano /root/.smbcredentials
Set the samba username and password to above file.
username=smb_username password=smb_password
- Step 4 – Use the following command to mount remote samba share on a Linux system.
sudo mount -t cifs -o rw,vers=3.0,credentials=/root/.smbcredentials //192.168.1.10/share /media/share
But the manually mounted file system will not remain mounted after a system reboot. To mount samba share automatically after system reboot, complete next step.
- Step 5 –You can make add the configuration to
/etc/fstab
file to auto mount remote share on system boot.Edit the below configuration file in your favorite text editor:
sudo nano /etc/fstab
Add the line at end of the file as follows. Change values as per yours.
//192.168.1.10/share /media/share cifs vers=3.0,credentials=/.smbcredentials
Conclusion
In this tutorial, you have learned to mount remote samba share on Unix like system. Also enabled to mount remote share on system boot.
Note that the option “vers=2.0” (or another version number) might be mandatory to choose the right protocol version to match the one of the server.
@ANDY D
I too faced the same problem.
Solution found is,
sudo nano /.smbcredentials
username=machine
password=machine
Save
sudo nano /etc/fstab
Add following line:
//192.168.159.133/share_host/ /share_mount/ cifs vers=3.0,credentials=/.smbcredentials
Save & Reboot
I haven’t tried this, but surely there’s a typo in the instructions.
He says: “sudo mkdir /media/Share” (with uppercase “S”)
Later in the fstab example given, the directory is addressed as “…/media/share…” with lowercase “s”
My understanding is that Liunx, unlike Windows, distinguishes between upper and lower case, in which case the address in the fstab example would fail to find the previously created address because of the case discrepancy.
Guess they don’t teach how to secure a credential file at Red Hat Certified Engineer courses so it is not readable by everyone on the computer?
I had to remove “sec=ntlm” from the options to get this to work, also on Ubuntu.
Hi, I have tried following these instructions, but I am getting the following error:
mount error(22): Invalid argument
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
I am using gifs-utils version (2:6.8-1) running on Ubuntu 18.04.2 LTS.
Can you please advise on what I am doing wrong?
I wonder how much different it is for CentOS?