This page looks best with JavaScript enabled

Flexibly Mount Network Shares on Login

 ·  ☕ 2 min read

Background

There are several guides out there showing how to mount network shares, some distro’s (Ubuntu) come with built-in tools/plugins (e.g. nautilus and others) to do this but I’ve found the following approach works better across multiple distro’s and desktop managers (I prefer openbox or xfce and do not like the overhead of nautilus). The following approach works well with any file manager or the command line as it uses samba (smbfs) to mount a network share as a local mount point.

Details

  • Install smbfs and winbind
    • sudo apt-get install smbfs winbind
  • Make your mount point
    • sudo mkdir /media/sharename
  • To mount by netbios name:
    • sudo nano /etc/nsswitch.conf
    • add ‘wins’ (no ticks) like the following: "hosts: files mdns4_minimal [NOTFOUND=return] wins dns mdns4"
    • restart network sudo /etc/init.d/networking restart
  • Make your ‘credentials’ file (this stores your username/pwd for the network share so you do not have to enter it upon mounting the share. Put it in the /root dir and restrict who can rw the file
    • sudo nano /root/.smbcredentials
    • add in the following two lines:
1
2
    username=share-username-goes-here
    password=share-password-goes-here
+ sudo chmod 700 /root/.smbcredentials
  • Edit fstab to automatically mount network directories:
1
//netbiosname/sharename    /media/sharename        cifs    credentials=/root/.smbcredentials,iocharset=utf8,file_mode=0777,dir_mode=0777,uid=1000,mask=000 0 0
  • Mount the shares (note: they will be automounted on login from this point forward)
    • sudo mount -a
Share on

drad
WRITTEN BY
drad
Sr. Consultant