Create articles from any YouTube video or use our API to get YouTube transcriptions
Start for freeIntroduction
Network-attached storage (NAS) devices like Synology offer convenient centralized file storage, but accessing those files seamlessly across multiple devices can be challenging. This guide will walk you through the process of automatically mounting SMB (Server Message Block) shares from your Synology NAS onto any Linux system, including virtual machines and Raspberry Pis.
By following this tutorial, you'll be able to access your NAS files as if they were local storage, persisting across reboots and providing a seamless experience for your Linux systems.
Why Auto-Mount SMB Shares?
Auto-mounting SMB shares offers several benefits:
- Convenience: Access your NAS files without manually connecting each time you boot your system.
- Seamless integration: Use NAS storage as if it were local, allowing for easy file management and backups.
- Improved workflow: Automate processes that involve NAS files, such as photo backups or media streaming.
Prerequisites
Before we begin, make sure you have:
- A Synology NAS with SMB enabled
- A Linux system (physical or virtual) with network access to the NAS
- Administrative access to both the Synology DSM and your Linux system
Step 1: Configure Synology NAS
Enable SMB and Create a User
- Log into your Synology DSM (DiskStation Manager)
- Navigate to Control Panel
- Create a new user:
- Click "User" and then "Create"
- Set a username and password (e.g., username: "smbuser", password: "test1234")
- Assign limited permissions to specific shared folders
- Deny unnecessary privileges for increased security
- Ensure SMB is enabled:
- In Control Panel, check that the SMB service is running
Set a Static IP for Your NAS
For easier connections, assign a static IP address to your Synology NAS. This step is optional but recommended.
Step 2: Prepare Your Linux System
Install CIFS Utilities
CIFS (Common Internet File System) utilities allow Linux to connect to SMB shares. Install them using the following commands:
sudo apt-get update
sudo apt-get install cifs-utils
Create a Mount Point
Choose a location to mount your SMB share. For this example, we'll create a directory in the user's home folder:
mkdir ~/server
Determine User ID
Find your Linux user ID with the following command:
id
Note the UID value (usually 1000 for the first user).
Step 3: Manual Mount Test
Before setting up auto-mounting, let's test a manual mount to ensure everything is working correctly.
sudo mount -t cifs -o username=smbuser,password=test1234,uid=1000 //192.168.1.123/sharename /home/user/server
Replace the following with your specific details:
-
smbuser
: The username you created on the Synology NAS -
test1234
: The password for that user -
1000
: Your Linux user ID -
192.168.1.123
: The IP address of your Synology NAS -
/sharename
: The name of the shared folder on your NAS -
/home/user/server
: The mount point on your Linux system
If successful, you should now be able to access your NAS files in the /home/user/server
directory.
Step 4: Set Up Auto-Mounting
Create a Credentials File
To avoid storing your password in plain text, create a credentials file:
sudo nano /root/.smbcredentials
Add the following content:
username=smbuser
password=test1234
Save and exit the editor (Ctrl+X, then Y, then Enter).
Secure the file so only root can access it:
sudo chmod 600 /root/.smbcredentials
Edit fstab
Now, we'll edit the filesystem table (fstab) to set up auto-mounting:
sudo nano /etc/fstab
Add the following line at the end of the file:
//192.168.1.123/sharename /home/user/server cifs credentials=/root/.smbcredentials,uid=1000 0 0
Make sure to replace the placeholders with your specific details.
Save and exit the editor.
Step 5: Test Auto-Mounting
To test if auto-mounting works without rebooting, run:
sudo mount -a
If successful, you should be able to access your NAS files in the mount point directory.
Finally, reboot your Linux system to ensure the auto-mount persists across restarts.
Troubleshooting
Spaces in Share Names
If your share name contains spaces, you'll need to use the proper escape sequence in the fstab file. Replace spaces with \040
. For example:
//192.168.1.123/My\040Photos /home/user/server cifs credentials=/root/.smbcredentials,uid=1000 0 0
Connection Issues
If you can't connect to the network during boot or experience other issues, you can manually remount the shares using:
sudo mount -a
Permission Denied Errors
If you encounter "Permission denied" errors, double-check the following:
- The credentials in your
.smbcredentials
file are correct - The user on your Synology NAS has the necessary permissions for the shared folder
- The
uid
in the fstab entry matches your Linux user ID
Security Considerations
- Use a dedicated user: Create a separate user on your Synology NAS for SMB access with minimal necessary permissions.
- Encrypt credentials: Always use the credentials file method instead of putting the username and password directly in the fstab entry.
- Use strong passwords: Ensure the SMB user has a strong, unique password.
- Limit share access: Only mount the specific shares you need, not the entire NAS.
- Keep software updated: Regularly update both your Synology NAS and Linux system to patch security vulnerabilities.
Advanced Usage
Mounting Multiple Shares
You can mount multiple SMB shares by adding additional lines to your fstab file. Each share should have its own mount point.
Using Groups for Access Control
Instead of specifying a uid
in the mount options, you can use gid
to assign access to a specific group. This is useful when multiple users need access to the mounted share.
Optimizing Performance
You can add additional mount options to optimize performance:
//192.168.1.123/sharename /home/user/server cifs credentials=/root/.smbcredentials,uid=1000,iocharset=utf8,file_mode=0777,dir_mode=0777,vers=3.0 0 0
These options set the character set, file and directory permissions, and SMB protocol version.
Conclusion
Auto-mounting SMB shares from your Synology NAS to Linux systems provides a seamless way to access your network storage. By following this guide, you've learned how to:
- Configure your Synology NAS for SMB access
- Prepare your Linux system with the necessary utilities
- Test manual mounting of SMB shares
- Set up secure auto-mounting using fstab and credential files
- Troubleshoot common issues and optimize your setup
With this knowledge, you can now integrate your NAS storage more effectively into your Linux workflows, whether you're using it for backups, media streaming, or collaborative file sharing.
Remember to always prioritize security when setting up network storage access, and regularly review and update your configurations to ensure they meet your changing needs and security requirements.
Further Reading
- Synology DSM User's Guide: For more information on configuring your NAS
- Linux man pages for mount.cifs and fstab: Detailed documentation on mount options and fstab syntax
- Samba Project Documentation: In-depth information on SMB/CIFS protocols and implementation
By mastering the auto-mounting of SMB shares, you've taken a significant step towards a more integrated and efficient network storage solution for your Linux environment.
Article created from: https://www.youtube.com/watch?v=RIS482WvbM4