About Linux FAQ

Browse More FAQs:

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

Posted by Vivek Gite [Last updated: October 2, 2006]

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.

Capture each and every moment of life with a FREE 4 GB SD memory card with the purchase of select digital cameras from Canon, Nikon, Pentax and others from Amazon

E-mail    Print    Can't find an answer to your question? Contact us

Related Other Helpful FAQs:

Discussion on This FAQ

  1. Scott Says:

    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 Says:

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

  3. nixcraft Says:

    Martial,

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

    http://www.cyberciti.biz/faq/access-windows-shares-from-linux/

  4. mark Says:

    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.

    http://gentoo-wiki.com/HOWTO_Auto_mount_filesystems_(AUTOFS)

  5. Ali Says:

    first create the below in root home directory:

    cd
    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=D1Y4×9sw 0 0

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

  6. Phil Says:

    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 Says:

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

  8. Phil Says:

    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 Says:

    Thank you for information

  10. curious mounter Says:

    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 Says:

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

  12. loopo Says:

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

    -> man mount.cifs (line 85)

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Powered by Open source software.