Mount Samba Shares Permanently: Difference between revisions

From WikiMLT
m (Стадий: 6 [Фаза:Утвърждаване, Статус:Утвърден]; Категория:Linux Server)
 
Line 5: Line 5:
sudo apt update && sudo apt install cifs-utils
sudo apt update && sudo apt install cifs-utils
</syntaxhighlight>
</syntaxhighlight>
== Mounting unprotected (guest) network folders ==
== Mounting unprotected (guest) network folders ==
'''1.''' Create a mounting directory.<syntaxhighlight lang="shell" line="1">
'''1.''' Create a mounting directory.<syntaxhighlight lang="shell" line="1">
Line 14: Line 13:
//192.168.1.110/share/  /home/share-desktop-x  cifs  guest,uid=1000,iocharset=utf8,nofail  0  0
//192.168.1.110/share/  /home/share-desktop-x  cifs  guest,uid=1000,iocharset=utf8,nofail  0  0
</syntaxhighlight>
</syntaxhighlight>
* <code>guest</code> indicates you don't need a password to access the share,
* <code>guest</code> indicates you don't need a password to access the share,
* <code>uid=1000</code> makes the Linux user specified by the id the owner of the mounted share, allowing them to rename files,
* <code>uid=1000</code> makes the Linux user specified by the id the owner of the mounted share, allowing them to rename files,
Line 20: Line 18:
* <code>nofail</code> allows the system to boot properly when the minting device (volume, share) is not avalilable.
* <code>nofail</code> allows the system to boot properly when the minting device (volume, share) is not avalilable.
* If there is any space in the server path, you need to replace it by <code>\040</code>, for example <code>//servername/My\040Documents</code>.
* If there is any space in the server path, you need to replace it by <code>\040</code>, for example <code>//servername/My\040Documents</code>.
'''3.''' Remount the entries listed in <code>/etc/fstab</code>.<syntaxhighlight lang="shell" line="1">
'''3.''' Remount the entries listed in <code>/etc/fstab</code>.<syntaxhighlight lang="shell" line="1">
sudo mount -a
sudo mount -a
</syntaxhighlight>
</syntaxhighlight>
== Mount password protected network folders ==
== Mount password protected network folders ==
'''A.''' Add the conditionals as plain text in <code>/etc/fstab</code>. This is the quickest and most unsafe approach.
'''A.''' Add the conditionals as plain text in <code>/etc/fstab</code>. This is the quickest and most unsafe approach.
Line 35: Line 31:
sudo mount -a
sudo mount -a
</syntaxhighlight>'''B.''' By using <code>~/.smbcredentials</code>.  
</syntaxhighlight>'''B.''' By using <code>~/.smbcredentials</code>.  
'''B.1.''' Create this file wit content as follow, ad set restrictive permissions.
'''B.1.''' Create this file wit content as follow, ad set restrictive permissions.
<syntaxhighlight lang="shell" class="mlw-continue" line="1">
<syntaxhighlight lang="shell" class="mlw-continue" line="1">
Line 55: Line 50:
sudo mount -a
sudo mount -a
</syntaxhighlight>
</syntaxhighlight>
== References ==
== References ==
 
* Ubuntu Wiki: [https://wiki.ubuntu.com/MountWindowsSharesPermanently '''Mount Windows Shares Permanently'''] - This is the main source, it contains more explanations, including: a) Special permissions; b) Mount password protected shares using <code>libpam_mount</code>; c) Troubleshooting. Here is a [[:File:UbuntuWiki - MountWindowsSharesPermanently.pdf|local copy of the article]].
* Ubuntu Wiki: [https://wiki.ubuntu.com/MountWindowsSharesPermanently '''Mount Windows Shares Permanently'''] - This is the main source, it contains more explanations, including: a) Special permissions; b) Mount password protected shares using <code>libpam_mount</code>; c) Troubleshooting.
 
<noinclude>
<noinclude>
<div id='devStage'>
<div id='devStage'>

Revision as of 15:03, 5 August 2022

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