ubuntu:mount:mount_a_network_share_with_a_credentials_file_and_on-demand_mounting
Table of Contents
Ubuntu - Mount - Mount a Network Share with a Credentials file and On-Demand Mounting
- A protected credentials file is used to store the username and password.
- On-demand mounting - The shares will not be mounted at boot but instead will be mounted the first time the directory is accessed.
Create the Credentials file
sudo mkdir /root/.credentials
NOTE: This directory will store the credentials files.
Set Directory Permissions
sudo chmod 700 /root/.credentials
NOTE: To ensure that only root can access this directory.
Configure the Credentials File
Edit the /root/.credentials/server-credentials file and populate:
- /root/.credentials/server-credentials
username=peter password=PASSWORD
NOTE: Replace PASSWORD with the actual value for the server!
Set File Permissions
chmod 600 /root/.credentials/server-credentials
NOTE: This ensures that only root can read this file.
Create the Local Share Directory
sudo mkdir /mnt/server/share
Obtain the UID and GID
id -u peter id -g peter
Set the Owner of this Share
sudo chown UID:GID /mnt/server/share
NOTE: Replacing UID:GID with the actual values returned from the previous step.
Edit fstab
Add the following line to the bottom of the file:
- /etc/fstab
//server/share /mnt/server/share cifs uid=UID,gid=GID,credentials=/root/.credentials/server-credentials
NOTE: Replace UID and GID with the User Id and Group Id found earlier.
Test
sudo mount -a
NOTE: This reloads the fstab file.
cd /mnt/server/share ls
NOTE: This should show the files in the share.
ubuntu/mount/mount_a_network_share_with_a_credentials_file_and_on-demand_mounting.txt · Last modified: 2021/07/05 09:24 by peter