Skip to content

Instantly share code, notes, and snippets.

@butageek
Created February 15, 2022 00:09
Show Gist options
  • Save butageek/d28208b38959fbcdb7520025b996f58b to your computer and use it in GitHub Desktop.
Save butageek/d28208b38959fbcdb7520025b996f58b to your computer and use it in GitHub Desktop.
Mount SMB Share in Ubuntu

CIFS installation

sudo apt-get install cifs-utils

Mount password protected network folders

The quickest way to auto-mounting a password-protected share is to edit /etc/fstab (with root privileges), to add this line:

//servername/sharename  /media/windowsshare  cifs  username=msusername,password=mspassword,iocharset=utf8 0 0

This is not a good idea however: /etc/fstab is readable by everyone and so is your Windows password in it. The way around this is to use a credentials file. This is a file that contains just the username and password.

Using a text editor, create a file for your remote servers logon credential:

gedit ~/.smbcredentials

Enter your Windows username and password in the file:

username=msusername
password=mspassword

Save the file, exit the editor.

Change the permissions of the file to prevent unwanted access to your credentials:

chmod 600 ~/.smbcredentials

Then edit your /etc/fstab file (with root privileges) to add this line (replacing the insecure line in the example above, if you added it):

//servername/sharename /media/windowsshare cifs credentials=/home/ubuntuusername/.smbcredentials,iocharset=utf8 0 0

Save the file, exit the editor.

Finally, test the fstab entry by issuing:

sudo mount -a

If there are no errors, you should test how it works after a reboot. Your remote share should mount automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment