🗃️

How To: 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


						
ℹ️ Replace CREDFILENAME with a filename of your choice but make sure there is a . at the start of the filename.

Open the file and enter the following contents:


username=SHAREUSERNAME
password=SHAREPASSWORD


						
ℹ️ Replace SHAREUSERNAME with the username to access the Windows File Share.
ℹ️ Replace SHAREUSERNAME with the username to access the Windows File Share.

To secure the credentials file restrict access to only the root user, run:


sudo chmod 600 /root/.CREDFILENAME


						
ℹ️ Use the CREDFILENAME from the earlier step.
⚠️ You may want to take other security precautions with your CREDFILENAME file.

Mounting

Create a folder to mount the Windows File Share:


sudo mkdir /FOLDER/AS/MOUNTPOINT


						
ℹ️ Replace /FOLDER/AS/MOUNTPOINT with the path for the Windows File Share to be mounted.

Automatically

Configure the mount point by adding details to /etc/fstab:


//SHARESERVER/SHARENAME /FOLDER/AS/MOUNTPOINT cifs credentials=/root/.CREDFILENAME, 0 0


						
ℹ️ Replace
  • 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


						
ℹ️ Replace /FOLDER/AS/MOUNTPOINT with the path from the earlier step.

Tested on Ubuntu Server Linux 22.04