Setup a Connection to a Windows File Share from a Linux Server
It’s usually quite easy to connect to a Windows File Share on desktop versions of Linux however Linux servers often run with no Graphical User Interface (GUI). They also often run for months, even years, at a time with no user intervention. This makes connecting to a Windows File Share a little bit more complicated but not impossible.
Prerequisites
Before proceeding you will need to have installed:
-
Samba
-
Samba Client (
smbclient
) -
CIFS Utilities (
cifs-utils
)
To install these on Ubuntu Server Linux, run:
sudo apt install samba smbclient cifs-utils -y
Credentials
To prevent having to put a username and password details in every time the connection is established, create a credential files:
sudo touch /root/.CREDFILENAME
Open the file and enter the following contents:
username=SHAREUSERNAME
password=SHAREPASSWORD
To secure the credentials file restrict access to only the root user, run:
sudo chmod 600 /root/.CREDFILENAME
Mounting
Create a folder to mount the Windows File Share:
sudo mkdir /FOLDER/AS/MOUNTPOINT
Automatically
Configure the mount point by adding details to
/etc/fstab
:
//SHARESERVER/SHARENAME /FOLDER/AS/MOUNTPOINT cifs credentials=/root/.CREDFILENAME, 0 0
-
SHARESERVER
with the server of the Windows File Share.
-
SHARENAME
with the folder of the Windows File Share.
-
/FOLDER/AS/MOUNTPOINT
with the path from the earlier step.
-
CREDFILENAME
with the filename from the earlier step.
This will automatically mount the Windows File Share at start up without requiring login or any user interaction.
Manually
Mount
To mount the newly configured Windows File Share without have to reboot, run:
sudo mount -a
Unmount
To unmount the Windows File Share, run:
sudo umount /FOLDER/AS/MOUNTPOINT
Tested on Ubuntu Server Linux 22.04