Debian, Home Server, Linux

Mount CIFS shares with credentials file

How to mount a CIFS-network-share with a credentials file.

When you are working with virtual machines, mounting network drives is an important task. Mounting drives can be done manually, but when setting up a home-server, things like this should happen automatically.

Mounting CIFS-share without permissions:
Create a mountpoint:
sudo mkdir /mnt/files
Mount the share to the mountpoint:
sudo mount // /mnt/files

Mounting CIFS-share with permissions:
Create a mountpoint
sudo mkdir /mnt/files
Mount the share to the mountpoint:
sudo mount // /mnt/files -o username=username,password=password

Mounting CIFS-share with permissions in fstab with credentials file and automount when booting:
Create a mountpoint
sudo mkdir /mnt/files
Create a credentials file (the “.” before the file name makes it hidden)
sudo nano /home/user/.credentials

The credentials-file should look like this:

sudo nano /etc/fstab
In the fstab-file you add:
// /mnt/files cifs credentials=/home/user/.credentials,noauto,x-systemd.automount,_netdev,uid=pievdb,noperm,rw 0 0

Press CTRL-X, confirm with Y, press enter.

Tagged , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *