If you manage a mixed-OS environment, you frequently need your Linux servers to communicate with Windows file servers. You can manually mount a Windows Shared Folder (SMB/CIFS) by typing a complex mount command in the terminal. However, the exact second the Linux server reboots, the connection is instantly severed, and you have to type the command all over again.
To create a permanent, persistent connection that automatically reconnects every time the Linux machine boots up, you must hardcode the network location directly into the Linux File System Table (/etc/fstab).
Step 1: Install the CIFS Utilities
Before Linux can understand the proprietary Windows SMB protocol, it needs the correct translation libraries.
- Open your Linux terminal.
- Run the package manager to install the CIFS utilities:
- For Ubuntu/Debian:
sudo apt install cifs-utils - For RHEL/CentOS:
sudo yum install cifs-utils
- For Ubuntu/Debian:
Step 2: Create the Local Mount Point
Linux needs an empty physical folder on its own hard drive to act as the “doorway” to the Windows server.
- Create a new directory in the
/mntfolder:sudo mkdir -p /mnt/windows_share
Step 3: Create a Secure Credentials File
You should never type your Windows password directly in plaintext into the fstab file, as that file is readable by all users on the system. You must create a hidden credentials file.
- Create a hidden file in your root directory:
sudo nano /root/.smbcredentials - Add your Windows username and password exactly like this:
username=your_windows_username password=your_windows_password domain=YOUR_DOMAIN (optional) - Save and exit nano (Ctrl+O, Enter, Ctrl+X).
- Lock down the permissions so only the root user can read the file:
sudo chmod 600 /root/.smbcredentials
Step 4: Hardcode the fstab Entry
Now, you will inject the persistent mounting rule into the File System Table.
- Open the fstab file in nano:
sudo nano /etc/fstab - Scroll to the absolute bottom of the file and paste the following line (all on one single line). Replace the IP address with your actual Windows Server IP:
//192.168.1.100/SharedFolder /mnt/windows_share cifs credentials=/root/.smbcredentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0 - Save and exit nano.
The Result
To test if your configuration is perfect without having to reboot the server, simply run:
sudo mount -a
This commands Linux to read the fstab file and instantly mount anything that isn’t already connected. If you receive no error messages, type ls /mnt/windows_share. You will instantly see all the files hosted on your remote Windows server. Moving forward, the Linux kernel will automatically execute this connection within seconds of booting up, guaranteeing persistent cross-platform file access.