Mount Samba Shares Permanently

From WikiMLT

Template:ContentArticleHeader/Network Se­cu­ri­ty

Pre­req­ui­sites

CIFS in­stal­la­tion.

sudo apt update && sudo apt install cifs-utils

Mount­ing un­pro­tect­ed (guest) net­work fold­ers

1. Cre­ate a mount­ing di­rec­to­ry.

sudo mkdir /home/share-desktop-x

2. Add the fol­low­ing line to /​​​etc/​​​fstab.

sudo nano /etc/fstab
//192.168.1.110/share/   /home/share-desktop-x   cifs  guest,uid=1000,iocharset=utf8,nofail  0  0
  • guest in­di­cates you don't need a pass­word to ac­cess the share,
  • uid=1000 makes the Lin­ux user spec­i­fied by the id the own­er of the mount­ed share, al­low­ing them to re­name files,
  • iocharset=utf8 al­lows ac­cess to files with names in non-Eng­lish lan­guages. This doesn't work with shares of de­vices like the Buf­fa­lo Tera Sta­tion, or Win­dows ma­chines that ex­port their shares us­ing ISO8895-15,
  • no­fail al­lows the sys­tem to boot prop­er­ly when the mint­ing de­vice (vol­ume, share) is not avalil­able.
  • If there is any space in the serv­er path, you need to re­place it by \040, for ex­am­ple //servername/My\040Documents.

3. Re­mount the en­tries list­ed in /​​​etc/​​​fstab.

sudo mount -a

Mount pass­word pro­tect­ed net­work fold­ers

A. Add the con­di­tion­als as plain text in /​​​etc/​​​fstab. This is the quick­est and most un­safe ap­proach.

sudo nano /etc/fstab
//192.168.1.110/share/   /home/share-desktop-x   cifs  username=<user>,password=<passwd>,uid=1000,iocharset=utf8,nofail  0  0
sudo mount -a

B. By us­ing ~/.smbcredentials.

B.1. Cre­ate this file wit con­tent as fol­low, ad set re­stric­tive per­mis­sions.

nano ~/.smbcredentials
username=<user>
password=<passwd>
chmod 600 ~/.smbcredentials

B.2. Mod­i­fy or add the rel­e­vant line in the fol­low­ing line to /​​​etc/​​​fstab and re­mount.

sudo nano /etc/fstab
//192.168.1.110/share/   /home/share-desktop-x   cifs  credentials=/home/<user>/.smbcredentials,uid=1000,iocharset=utf8,nofail  0  0
sudo mount -a

Ref­er­ences