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

by on April 25, 2006 · 34 comments· LAST UPDATED October 2, 2006

in , ,

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

/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 0Where,

  • //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.

Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 34 comments… read them below or add one }

1 Scott November 7, 2006 at 9:19 pm

Okay, but the use of the term “automount” here
is misleading. I was looking for how to configure
autofs to work with samba shares.


2 Martial November 27, 2006 at 4:56 pm

It disturb me that username and passwd appears clearly in the fstab file. Is there another solution ?


3 nixCraft November 27, 2006 at 5:29 pm


Try to put password/username in different file and make sure password file is only accessed by root. See url for an example:


4 mark February 15, 2007 at 5:17 pm

I have to agree with Scott, “automount” in the title is misleading. I too was looking for info on configuring samba with autofs.

The following link might be useful to Scott and also has details on moving the username/password to a different file.


5 Ali February 19, 2007 at 4:28 am

first create the below in root home directory:

echo username=mywindowsusername > .smbpasswd
echo password=mywindowspassword >> .smbpasswd
chmod 600 .smbpasswd

Then the below line will be changed:
//ntserver/docs /mnt/samba smbfs username=docsadm,password=D1Y4x9sw 0 0

To :
//servername/sharename /mountdirectory smbfs credentials=/home/myhomedirectory/.smbpasswd 0 0


6 Phil April 26, 2007 at 6:46 pm

I’ve put the entry in fstab and put the credentials in another file. It works fine, thank you, but although I can write to the share as root, I can’t as a normal user. I’ve tried chmod on the mount point, but that didn’t work, any ideas?


7 Adi April 27, 2007 at 10:05 am

try this:
//servername/sharename /mountdirectory smbfs credentials=/home/myhomedirectory/.smbpasswd,uid=user,gid=user 0 0


8 Phil April 28, 2007 at 12:49 pm

Thanks for the feedback. This actually prompted me to do a little more research on the options and as this share is just a dumping ground I decided to use

//servername/sharename /mountdirectory smbfs credentials=/home/myhomedirectory/.smbpasswd,fmask=666,dmask=777 0 0

so that it’s writeable by everyone.


9 sudeep July 26, 2007 at 6:47 am

Thank you for information


10 curious mounter March 4, 2008 at 6:46 am

I’d like to ask a question and I don’t think the solution is out there….I have a samba share setup that will only allow connections from my LAN IP addresses…therefore, I don’t need user/pass security setup on it.

I have configured it as an open share writeable and readable by anyone connecting from MY LAN. This works through browsing local network in KDE/Gnome or even in Windows. This is nice for my friends who come by and want to connect to my music/movie/game share.

However, I cannot configure a Linux /etc/fstab to mount the share because it keeps asking for a username and password. There IS NO USERNAME nor PASSWORD. So, how does one enter the information so that it can be processed and mounted by fstab?

I think this would be a great ‘how-to’ for you to feature like this article…because there is NOTHING out there on how to do this.


11 John March 17, 2008 at 9:21 pm

yeah, i am also looking for a solution to the no username/password access to a windows share…


12 loopo March 24, 2008 at 2:21 am

@John and curious mounter
the “guest”-option will do.

-> man mount.cifs (line 85)


13 selvam December 11, 2008 at 10:58 am

i want shared data from windows to linux system.. how can i share different way. plz any one mail to me.
same time i want to modified my pdf file. any pdf writer in linux plz intimated me.



14 manikandan March 20, 2009 at 6:27 pm

i want shared data from windows to linux system.. how can i share different way. plz any one mail to me.
same time i want to modified my pdf file. any pdf writer in linux plz intimated me.

Manikandan KM


15 Bud March 30, 2009 at 6:27 pm

loopo, I got excited at the NO USERNAME/NO PASSWORD discussion raised by John and curious mounter, and I appreciate your response that “the “guest”-option will do. -> man mount.cifs (line 85)”, but as I’m a growing newbie, I’m not sure how to apply your response (though I think I understood all the thread up to the point that you responded about the guest option and the arrow point). Currently, Dolphin has no problem accessing my DLink NAS (well, at first it stumbles and doesn’t recognize it, but after I go to Network and work my way to it, it appears with my bookmark, though sometimes it doesn’t even appear under Network until I go to Firefox and use the call, then it “suddenly” appears when I return to Network — I guess it’s one of those mounting things).

I note that Konqueror seems unable to work with to configure the NAS, but Firefox always has no trouble with this.

Maybe this is a different problem (or maybe it’s related to the fstab needing to be done first), but what I MOST want to do is have programs (VLC, K9, etc.) to be able to access my DLink NAS, but they seem blind to it through their file access dialog boxes. For example, VLC plays DVD iso’s just fine if it is on a local drive and I drag-&-drop it from Dolphin, but if it is on my NAS, VLC does not recognize the file unless I first copy it with Dolphin to a local drive, then after a drag-&-drop from the local drive, it plays just fine (again, it’s a DVD iso). I’d also like to use K9 to put DVD iso’s directly on the NAS (instead of running them to a local drive from K9 and then later copying them to the NAS for storage), but K9 just doesn’t seem to acknowledge that the NAS exists through its dialog boxes (though Dolphin shows it’s there plain as day after it’s mounted).

If I do the fstab trick in this thread (well, once I understand how to apply your solution), will it solve my problem with VLC & K9, etc.? I have NO NAME & NO PASSWORD like the previous writers mentioned on my NAS so everyone in the house can use it (all the dual-boot Windows based computers on the network have no difficulty whatsoever with the NAS with VLC etc., it’s just the dual-boot Linux systems that stumble from their dialog boxes in a variety of Linux-based programs that are very important to us — we’re trying to get away from Windows completely but we haven’t learned how to do some things with Linux yet).


16 Steve April 20, 2009 at 8:18 am

I am also using the “ip instead of password” idea.

If I am reading this right, user “guest” as the username and leave off the password.

specifies the CIFS password. If this option is not given then the environment variable PASSWD is used. If the password is not specified directly or indirectly via an argument to mount mount.cifs will prompt for a password, unless the guest option is specified.

and guest described…
don’t prompt for a password </cite


17 Kostas August 11, 2009 at 11:19 am

Beware that if you add an option like “user” to fstab then a simple user can do:
mount –verbose /xxx and he will eventually see the username/password even if you used the credentials=… approach


18 Korla Plankton August 12, 2009 at 1:06 pm

People who want to automount specific shares for specific users when they log in should investigate the pam_mount library. It is secure and more appropriate on an untrusted network environment.

It’s a bit more complicated to set up than this, though. There are various tutorials out there and it can vary a little between the distros.


19 littlebear January 9, 2010 at 2:22 am

Wow, this tutorial is simple and easy for a beginner like me, the comments are especially helpful, although I use the parameter of rw,exec, user


20 Adam February 17, 2010 at 3:48 pm

How to make the /etc/fstab line work in Fedora 12? smbfs isn’t available.


21 JohnFen March 3, 2010 at 5:53 pm

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


22 Tracy July 20, 2010 at 7:05 pm

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



23 Srinivas Vemula August 20, 2010 at 7:44 am

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


24 Gernoth Klug September 10, 2010 at 9:32 am

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


25 Absy December 30, 2010 at 5:31 pm

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?



26 Johan February 9, 2011 at 4:58 pm



27 chusiang April 22, 2011 at 2:57 pm

Thanks your share, I get it :P


28 chusiang April 22, 2011 at 2:58 pm

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


29 OldManRiver May 13, 2011 at 4:52 pm


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.




30 G June 16, 2011 at 11:41 pm

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?


31 Leon July 13, 2011 at 8:08 am

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.


32 someguyfromgermany March 15, 2012 at 12:27 am

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



33 Renan July 19, 2013 at 8:13 pm

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?


34 Arrey April 23, 2014 at 7:52 pm

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



Leave a Comment

Tagged as:

Previous Faq:

Next Faq: