Mount Windows shared folders automatically with fstab
According to the article “Mounting smbfs Shares Permanently Help File” published on JustLinux by Ray Cowan, we could mount a Windows shared folder automatically using /etc/fstab. There are many discussions about how to do this on the internet. E.g. some people suggest using ~/.bashrc or ~/.bash_profile to fulfill this. But there are not the right solution. Because the mounting should only be done once not more. The essential thing in Ray’s article is one can use options of smbmount command in fstab. The working format looks like
//servername/sharename /mountdirectory smbfs credentials=/home/myhomedirectory/.smbpasswd,uid=myusername,gid=mygroupname 0 0
, where the ‘credentials’ option is given a value pointing to a text file containing Windows logon information, i.e. username and password.
This line in fstab ensure the automatic mounting during the system startup. It’s equivalent to
1 | sudo smbmount //servername/sharename /mountdirectory smbfs -o credentials=/home/myhomedirectory/.smbpasswd,uid=myusername,gid=mygroupname |
Note: the file .smbpasswd contains two lines, username=*** and passwd=*** for the Windows server. For security reason, this file should be viewable only to the yourself. Commad “chmod 600 /home/myhomedirectory/.smbpasswd” should be enough.

Leave a Reply