How to mount Windows share on Linux

Today I will show you how to mount SMB share on Debian 12 and make it persistent.

First of all, cifs-utils should be installed:

apt install cifs-utils

Next we need to create a mount point on Linux server. I will create “video” folder in root directory:

mkdir /video

SMB shares usually are not public and some credentials are required for access, so we are creating a file with username and password which will be used to mount the share.

nano /usr/share/smbcredentials

And put the following content inside:

username=user
password=password

Make sure to use your actual username and password.

Now we can mount the share:

mount -t cifs -o rw,vers=3.0,credentials=/usr/share/smbcredentials,dir_mode=0775,file_mode=0775,uid=1000,gid=1000 //192.168.1.10/video /video

Note that windows filesystem and share names are not case-sensitive, so the actual share name may cantain capital letters while here we are using lowercase.

To make this mount persistent, open the fstab:

nano /etc/fstab

And add following content at the end of the file:

//192.168.1.10/video /video cifs  rw,vers=3.0,credentials=/usr/share/smbcredentials,dir_mode=0775,file_mode=0775,uid=1000,gid=1000

Here dir_mode is mounted directory permissions, file_mode is default file permissions inside mouned share, uid and gid are share owner user and group id. So if you for example need to mount this share as www-data:www-data, you will use 33 for both uid and gid.

At this point you have a share mounted and ready to use!


Comments

Leave a Reply

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