Ethan Copping
How to Auto Mount CIFS/Samba Shares Linux Ubuntu on Boot
16, July 2022
Today we'll look at how to quickly and easily set up an Auto Mounted network share from your CIFS/Samba network share.
I'm personally using TrueNAS as my main storage solution, with the Windows Shares (SMB) option. This should virtually be the same process whether you're using a dedicated Hardware NAS like Synology or Software NAS like the built-in Windows File Sharing.
sudo apt install cifs-utils
- To get Auto Mounting to work on boot, we will need to supply credentials to your network share. To do this we need to create a credentials file on your system.
- Run the following command using your favourite text editor:
sudo nano /etc/netshare-creds
- You will now need to enter the following data using the username and password used to access your network share.
- If you don't have a domain setup, just leave it as domain.
domain=domain
username=username
password=password
- While you could store these as plain text, it's much better to secure them, making them unreadable by all users but root. Run the following two commands to set the permissions:
sudo chown root: /etc/netshare-creds
sudo chmod 600 /etc/netshare-creds
- We will need somewhere to mount the network share on your drive and for best practices, you should use an empty folder.
- For this example, I will mount the share in the /mnt directory in a folder called ShareName so our path will be /mnt/ShareName.
- For this, we need to create our folder. Simply run the following:
sudo mkdir /mnt/ShareName
- Now, let's tell your system to Auto Mount your network share.
- Using your favourite text editor run the following command:
sudo nano /etc/fstab
- Now enter the configuration below at the bottom of your fstab file:
//ShareIP/ShareName /mnt/ShareName cifs credentials=/etc/netshare-creds,file_mode=0755,dir_mode=0755 0 0
- That's it. 6 commands and 4 lines later, we have Auto Mounted setup.
- You can use the following command to mount your network share now:
sudo mount /mnt/ShareName
- or you can reboot your system and the share will appear.
© 2022 ethancopping.com