Mount Samba Shares Permanently
From WikiMLT
Template:ContentArticleHeader/Network Security
Prerequisites
CIFS installation.
sudo apt update && sudo apt install cifs-utils
Mounting unprotected (guest) network folders
1. Create a mounting directory.
sudo mkdir /home/share-desktop-x
2. Add the following 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
indicates you don't need a password to access the share,uid=1000
makes the Linux user specified by the id the owner of the mounted share, allowing them to rename files,iocharset=utf8
allows access to files with names in non-English languages. This doesn't work with shares of devices like the Buffalo Tera Station, or Windows machines that export their shares usingISO8895-15
,nofail
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
\040
, for example//servername/My\040Documents
.
3. Remount the entries listed in /etc/fstab
.
sudo mount -a
Mount password protected network folders
A. Add the conditionals as plain text in /etc/fstab
. This is the quickest and most unsafe approach.
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 using ~/.smbcredentials
.
B.1. Create this file wit content as follow, ad set restrictive permissions.
nano ~/.smbcredentials
username=<user>
password=<passwd>
chmod 600 ~/.smbcredentials
B.2. Modify or add the relevant line in the following line to /etc/fstab
and remount.
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
References
- Ubuntu Wiki: Mount Windows Shares Permanently – This is the main source, it contains more explanations, including: a) Special permissions; b) Mount password protected shares using
libpam_mount
; c) Troubleshooting. Here is a local copy of the article.