In this guide you'll learn how to mount a CIFS/SMB share on Ubuntu. Make sure you have your SMB server and credentials ready.
I advise you run the following as the root user. Especially step 4!
sudo apt install cifs-utils
This is the folder where you will mount the share to.
sudo mkdir /mnt/backups
Open your fstab file
(/etc/fstab). And add something like this to the bottom of the file.
//SERVER_IP_ADDRESS/SHARE_NAME /mnt/backups cifs username=msusername,password=mspassword,iocharset=utf8 0 0
You will note that you have enter the password and username here. This is not advisable since the
fstab file is readable by all users. Will fix this in the next step.
RUN THIS AS ROOT! Make this file in the home folder of root (by default
/root). Why? Because only root can access this folder or privileged users. This makes sure that other people cannot access the credentials file.
So create and open the file
/root/.smbcredentials using vim or nano. (Eg
sudo vi /root/.smbcredentials)
Save and close and then set the permissions that only root can read it.
sudo chmod 600 /root/.smbcredentials
You can verify it by writing:
sudo ls -al /root/.smbcredentials
If everything is correct you should see this:
Now open up your fstab again and replace the username and password with
Your file should look like this:
//SERVER_IP_ADDRESS/SHARE_NAME /mnt/backups cifs credentials=/root/.smbcredentials,iocharset=utf8 0 0
If you reboot the folder will be mounted automatically. Of course we can manually mount it by entering the command
sudo mount -a