Mounting Windows Shares On Linux Using Samba/CIFS/SMBFS

We have a colorful environment of Linux (Redhat/CentOS/SLES, and now Ubuntu) and Unix (well, not as colorful..mostly AIX). And a lot of heavy Windows use.

So I regularly get requests to mount windows shares on Linux/Unix systems.

What has inspired me to write this is working quite a bit longer than I expected on a new Ubuntu server to get it to mount a Windows share.

Here we go!

Mounting Windows on Linux and Unix Through Samba

This will be a quick and dirty for you.

Assuming you can talk to the ports and there is no firewall issue of some sort (and that the SMB service itself is working and open on the server), the main problem is usually authentication

Repeat: The main problem with Samba not working is usually authentication

Sponsored Links

The first thing is to check if authentication itself is working. I use the “smbclient” command for this. It usually has better output if something is not working (though these days you can mount with “–verbose” option and get a lot of nice output also)

smbclient \\\\machinename\\foldername -U [username] [password]

Note: Any special characters in your password, like a dollar sign, may need a backslash to escape.

If my password were “pa$$word”

smbclient \\\\machinename\\foldername -U [username] pa\$\$word

When you connect, it will put you in a “shell” similar to ftp or sftp where you can use commands “ls”, “put”, “get”, etc..

When ready to mount, you will either use filesystem type “smbfs” or “cifs” depending on if you are using an older linux kernel or newer linux kernel.

Sponsored Links

Older linux kernels:

# mount -t smbfs //servername/foldername /localmountpoint -o username=myusername,password=mypassword

Newer linux kernels:

# mount -t cifs //servername/foldername /localmountpoint -o username=myusername,password=mypassword

The above *should* work on CentOS/Redhat and SLES and I imagine other Linux versions

If you have to specify a workgroup or domain, then include a “dom=domainname” in the options field

e.g. username=myusername,dom=domainname,password=mypassword

Note, including password in the command line is only if you are going to automate it somehow and don’t want to be interactively asked for your password. If mounting manually, by all means don’t include the password!!


Ubuntu is my “special” case today..and is what inspired me to write this post since I worked a lot longer than I should have.

Turns out the default install does not let you do mount, and the error was slightly misleading (in hindsight it wasn’t). It did not give an error that “cifs” was not working, it gave an error that the remote disk could not be read and was going to mount it read-only.

But then it didn’t mount it

root@ubuntu:~# mount -t cifs //servername/share1 /share1 --verbose -o user=myuser,dom=domain
mount: block device // is write-protected, mounting read-only
mount: cannot mount block device // read-only

What I think it should have told me is an error like the below if you try to use “smbfs”

root@ubuntu:~# mount -t smbfs //servername/share1 /share1 --verbose -o user=myuser,dom=domain
mount: unknown filesystem type 'smbfs'

Turns out you need to install the smbfs package on Ubuntu for the CIFS mount to work.

# apt-get install smbfs

And then we were happy!

Although in my research, I have found some bugginess reported in that the “mount -t cifs” did NOT work, but using “mount.cifs” did .


mount -t cifs //servername/share1 /share1 --verbose -o user=myuser,dom=domain

Did not work


mount.cifs //servername/share1 /share1 --verbose -o user=myuser,dom=domain

Did work…

I wasn’t able to duplicate this particular issue, but yes … quite strange.

A last point

As most of the problems are authentication related, make sure you can actually authenticate.. Try from other machines, try from your windows machine, make sure the account is not locked!! (part of the issue I had today which compounded my debugging…arrrgghh!!)

That’s all!

So that’s the quick tutorial today! Good luck CIFS-ing and SMB-ing!

, , , , Linux, Windows

12 thoughts on “Mounting Windows Shares On Linux Using Samba/CIFS/SMBFS

  1. mount.cifs //servername/share1 /share1 –verbose -o user=myuser,dom=domain

    v. useful tip ! thank you.
    mount.cifs works where mount -t cifs doesnot.

  2. Is there any way to mount the servername on its own? I have a server, JRSERVER which has 17 shared folders. On a Windows PC, I can just type \\JRSERVER and have access to all 17 shared folders. This is what I need to do on Ubuntu, instead of having to mount 17 shares individually! Is this possible?

    • Hi JRS, So this is interesting because I’m not sure exactly how windows does it. On Linux, each folder is individual so yes I’d say you have to mount all 17.

      The best way to do many individual tasks in one swoop is to script it. However with mounting, you can also use the /etc/fstab file to mount on bootup

      You can do so at bootup by putting all the entires in /etc/fstab


      //servername/share1 /share1 cifs mountoptions 1 0
      //servername/share2 /share2 cifs mountoptions 1 0
      //servername/share3 /share3 cifs mountoptions 1 0

      The “mountoptions” are the tricky part, and you will likely have to put your credentials in, e.g.


      or you can keep your user/pass in a file such as /root/mylogininfo with these contents


      And change your fstab entry mountoptions to


      Which makes it slightly more secure

      So your final fstab entry would be something like

      //servername/share1 /share1 cifs domain=mydomain,credentials=/root/mylogininfo1 0
      //servername/share2 /share2 cifs domain=mydomain,credentials=/root/mylogininfo1 0
      //servername/share3 /share3 domain=mydomain,credentials=/root/mylogininfo1 0

      The other option is to put all your mount commands in a shell script such as /root/mountallwindows and call that script as needed

      mount.cifs //servername/share1 /share1 –verbose -o user=myuser,dom=domain
      mount.cifs //servername/share2 /share2 –verbose -o user=myuser,dom=domain
      mount.cifs //servername/share3 /share3 –verbose -o user=myuser,dom=domain

      When done, if you want to unmount, you can create a /root/umountallwindows script to unmount.

      umount /share1
      umount /share2
      umount /share3

      Does that help?

  3. I manually mount the following on a RHE system:

    mount -t cifs -o username=\$HP_Modular_SVC,password=,uid=,gid=modular,umask=770 //gszajnb693/EAM /dsp/cli/sio/opns/sapdata

    I cannot figure out how to put this into /etc/fstab

    Any pointers, ideas?

    • Hey there. Format would be
      //servername/sharepath /mountpoint fstype mountoptions 1 0

      In your example
      servername/sharepath = //gszajnb693/EAM
      mountpoint = /dsp/cli/sio/opns/sapdata
      FStype = cifs
      mountoptions = username=\$HP_Modular_SVC,password=,uid=,gid=modular,umask=770

      But you would put in the actual user/pass/uid/gid

      //gszajnb693/EAM /dsp/cli/sio/opns/sapdata cifs username=\$HP_Modular_SVC,password=,uid=,gid=modular,umask=770 1 0

      Hope that helps!

  4. can you please help.. I’m runing CentOS 6.6 and I found this post very helpful… I am able to mount my windows share manually no problem.. I would like to add this in the fstab file if possible to have it automatically connect on boot up… can you help.. here’s the command line I’m using in a terminal window that works fine… I will blank the passwords with stars..

    mount -t cifs //kenny/windows8 /mnt/Videos -o username=***,password=***

    How can I make this automatically happen on bootup


    • Hey there, you can put all those options in your /etc/fstab like below. You can put the username and password directly into /etc/fstab, or create a “credentials” file. See below

      Sample /etc/fstab entry:

      //kenny/windows8 /mnt/Videos cifs username=***,password=***, 0 0

      The fourth column are any of the other mount options you want to put in there as well.

      Sample fstab entry using a credentials file

      //kenny/windows8 /mnt/Videos cifs credentials=/root/kennycredentials 0 0

      And then the file /root/kennycredentials would contain this:


      Hope that helps!

  5. Just thought I’d note using Ubuntu (14.10 at the moment), smbfs has been deprecated so you must apt-get install cifs-utils to mount.

  6. I have 1 Free DOS computer and 1 Raspberry Pi, which is connect via LAN cable.
    One of the folder is shared in DOS. I am facing huge difficulty to get access to a shared drive.
    Below is the command i tried

    sudo -i mount -t cifs -o rw,netbiosname=DOSMCJA,user=username,guest,vers=1.0 //DOSMCJA/DAT /home/pi/myDOSMA/DOSMA
    I get mount error(104): connection reset by peer. or some time Host is down. I am searching for answer from 1 month. Please can you help me. more details can be found in my stack exchange question. Any additional details required please let me know

Leave a Comment

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

Spam protection by WP Captcha-Free