Configure a system to automount a Samba share with /etc/fstab

How do I configure a Linux based system to automount a Samba share on a Linux?

As explained earlier you can use the mount command to mount a remote windows partition or a windows share under Linux.

The /etc/fstab file contains static information about the filesystems. The file fstab contains descriptive information about the various file systems. fstab is only read by programs, and not written; it is the duty of the system administrator to properly create and maintain this file.

To mount a Samba share to be mounted when a Linux system comes up after reboot edit the /etc/fstab file and put entry as follows for your Windows/Samba share:
//ntserver/share /mnt/samba smbfs username=username,password=password 0 0

For example, if you want to mount a share called //ntserver/docs then you need to write following entry in /etc/fstab file:
//ntserver/docs /mnt/samba smbfs username=docsadm,password=D1Y4x9sw 0 0

  • //ntserver/docs: Windows 2003/NT/Samba share name
  • /mnt/samba: Local mount point (you may need to create this directory first)
  • smbfs: File system type (samba file system)
  • username=docsadm,password=D1Y4x9sw: Share username and password

Open file /etc/fstab using vi text editor:
# vi /etc/fstabAppend line
//ntserver/docs /mnt/samba smbfs username=docsadm,password=D1Y4x9sw 0 0, at the end your file should read as follows:

proc            /proc           proc    defaults        0       0
/dev/hdb1       /               ext3    defaults,errors=remount-ro 0       1
/dev/hdb2       none            swap    sw              0       0
/dev/hdc        /media/cdrom0   iso9660 ro,user,noauto  0       0
//ntserver/docs /mnt/samba      smbfs   username=docsadm,password=D1Y4x9sw 0 0

Replace sharename, username and password with your actual parameters.

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
36 comments… add one
  • JohnFen Mar 3, 2010 @ 17:53

    @adam: try “cifs” instead of “smbfs”

  • Tracy Jul 20, 2010 @ 19:05

    I have mounted a windows share before, however had a problem when the linux box was rebooted, the operating system would hang because the network had not connected in order to mount the windows share.

    So my question is this, how do you have the automount happen after the network connection?

    Here’s my fstab entry:

    //windowsshare/dir /mnt/point cifs rw,domain=DOMAIN,credentials=/path/filename,fmask=0664,dmask=0775


  • Srinivas Vemula Aug 20, 2010 @ 7:44

    Please also update or have a note that new linux systems might use CIFS file system.. then the conf would change to
    //ntserver/docs /mnt/samba cifs username=docsadm,password=D1Y4x9sw 0 0

  • Gernoth Klug Sep 10, 2010 @ 9:32

    Is is possible to use an ip address for share as well – for example:
    // /mnt/samba smbfs username=username,password=password 0 0

  • Absy Dec 30, 2010 @ 17:31

    guys, please I need help.
    I am not that expert in NFS, but what happened that I am runnning calculation on a pc cluster which is connected to NFS server called “//bourbon/home10” through another computer “hoppy”(the japanese people in my lab call it name server).
    what happened is this client computer”hoppy” gave an error and tried to automount old servers which were removed pretty while ago. it gives mounting error.
    and when I try to go to bourbon/home10 it doesnt show any subdirctories.
    any idea about what is happening here?


  • Johan Feb 9, 2011 @ 16:58


  • chusiang Apr 22, 2011 @ 14:57

    Thanks your share, I get it :P

  • chusiang Apr 22, 2011 @ 14:58

    by the way, I run it on Debian squeeze stable .

  • OldManRiver May 13, 2011 @ 16:52


    What I noticed is that the “fstab” runs at the beginning of the boot cycle to link the local hard drives and set up the needed filesystems, for the Linux to load, so eth0 has not run yet and therefore a network share, especially a windows share will not load, since networking is not yet established.

    I also noticed that since the SAMBA daemon runs later, after eth0 has run, then if the shares are correctly declared there, the windows network shares will link in, what I find missing is a good definition of how to set/call the a.) domain, b.) windowsusername, c.) windowsuserpwd within the smb.conf file.

    Since my flavor of Linux is Ubuntu I opened a thread on this at:

    Though I mentioned a script there, not stuck on that, if I can do it in the smb.conf file.



  • G Jun 16, 2011 @ 23:41

    Trying to auto-mount a Windows share with /etc/fstab but it’s not mounting.

    Format I am using includes a “space” in the share name, so I enclosed the windows share name in quotes, which works if I manually mount the share, but does not work with the fstab file. Any ideas how to accomplish this?

    • Leon Jul 13, 2011 @ 8:08

      I have the same situation, and then I tried to run following command after the fstab change:

      mount -a

      And then I can find the disk get mounted automatically, even reboot the system.

      • TienQuan May 5, 2017 @ 6:49

        You must alter every space in name by \040 charracter. By example:

        \\\My Share Folder

  • someguyfromgermany Mar 15, 2012 @ 0:27

    besides the topic ( which gave me alot of insights on the matter )
    its great to find such threads on the web 2006-2011 and still helpful.

    my problem was a bit different but thanks to various comments in this thread
    i got my stuff running and i just felt like thanking everyone for the insights

    keep up the good work


  • Renan Jul 19, 2013 @ 20:13

    What about mount two shared folders?
    I have tried this in /etc/fstab:
    // /mnt/folder1 cifs rw,user=guest,password=,uid=1000 0 0
    // /mnt/folder2 cifs rw,user=guest,password=,uid=1000 0 0

    After reboot, if I access the first folder “cd /mnt/folder1” and list files “ls”, my shared files are listed. If I try access folder2, nothing is listed. I reboot and tried again, but this time accessing “folder2” first, and then the files are listed. After, accessing “folder1” nothing is listed.

    In other words, it mount just the first accessed folder. Mounting it manually, “mount -all”, the two folders are mounted, but I need it to be mounted automatically at boot because these folders are used in services.

    How to mount more than one shared folder using fstab at boot?

  • Arrey Apr 23, 2014 @ 19:52

    What option do you include in fstab to prevent the server from handing if the cifs share is not available after reboot?


  • Sang Mar 7, 2016 @ 10:50

    Thanks, it works for me :)

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.