Mount a Windows Share Permanently on Linux

Posted on December 20th, 2013

Mounting a network drive isn't that difficult, but it can be confusing when you are trying to keep that share permanently mounted on your system. Usually, if you log out of your machine, or shut down, the drive will no longer be mounted on your system. Here is how you can keep that mount persistent, and never have to worry about mounting your network drive again.

Install CIFS
sudo apt-get install cifs-utils
Mount Unprotected Network Folders
First you must create your directory where you want to mount the share.
sudo mkdir /media/sharename
Next, open your fstab file.
sudo gedit /etc/fstab
Add the following line to your fstab:
  • //servername/sharename /media/sharename cifs guest,uid=1000,iocharset=utf8 0 0
You can now mount the drive.
sudo mount -a
Mount Password Protected Network Folders
First, you will want to create a file to hold your credentials for accessing the network folder.
gedit ~/.smbcredentials
Add the username and password to the network location like this:
  • username=yourusername
  • password=yourpassword
Simply save the file, and your credentials are now set up.
It may be a good idea to change permissions on the file, just as a safety precaution.
chmod 600 ~/.smbcredentials
Now you will want to open your fstab again (look above for how to open), and add the following line:
  • //servername/sharename /media/sharename cifs credentials=/home/username/.smbcredentials,iocharset=utf8,sec=ntlm 0 0
You can now mount the drive.
sudo mount -a
Your mounted drive should now stay on your system, even after rebooting your computer.

comments powered by Disqus
Andrew Backes

A Software Engineer living in Milwaukee, WI. Passionate about web/software development, tech, open source, and gaming.