I have this fstab entry to allow a tomcat app to read/write on a Windows Samba shared folder:

//dc/docs    /media/docs      cifs       credentials=...,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,sec=ntlm,uid=tomcat7,gid=tomcat7,dir_mode=0770,file_mode=0770 0 0

Problem is it keeps unmounting after a certain amount of time -- not a Windows failure, I can access the share elsewhere

$ sudo ls /media/docs
finance  postsale  repository

#after e.g. 10 minutes...
$ sudo ls /media/docs
[sudo] password for user:
ls: cannot access '/media/docs': Connection reset by peer

#this takes ages to complete
$ sudo umount /media/docs

#this fails immediately after, succedes after about 5/10 seconds
$ sudo mount /media/docs
mount error(112): Host is down
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
$ sudo mount /media/docs
mount error(104): Connection reset by peer
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
$ sudo mount /media/docs
$ sudo ls /media/docs
finance  postsale  repository

How do I debug this or prevent from dropping?

Tomcat app users have no rights to remount so everytime they need to rise a ticket to IT.

Please note this mount on the same share does not drop (only difference I spot is user is a sudoer while tomcat7 above is not):

//dc/share       /media/share     cifs       credentials=....credentials,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,sec=ntlm,uid=user,gid=user,dir_mode=0770,file_mode=0770 0 0


Folder /var/log/samba is empty -- how do I set logging for samba?

If I keep on listing the folder it does not drop:

while true; do date; ls /media/docs; sleep 5; done


Here the mount output:

//fs-mxp/ZZZshare on /media/share type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=XXX,domain=YYY-it,uid=1000,forceuid,gid=1000,forcegid,addr=,file_mode=0770,dir_mode=0770,nounix,serverino,mapposix,rsize=61440,wsize=65536,actimeo=1)
//fs-mxp/ftp on /media/ftp type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=XXX,domain=YYY-it,uid=1000,forceuid,gid=1000,forcegid,addr=,file_mode=0770,dir_mode=0770,nounix,serverino,mapposix,rsize=61440,wsize=65536,actimeo=1)
//sql-mxp/C$ on /media/sql type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=administrator,domain=YYY-it,uid=1000,forceuid,gid=1000,forcegid,addr=,file_mode=0770,dir_mode=0770,nounix,serverino,mapposix,rsize=61440,wsize=65536,actimeo=1)
//fs-mxp/ZZZdocs on /media/docs type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=YYYdoc,domain=YYY-it,uid=113,forceuid,gid=123,forcegid,addr=,file_mode=0770,dir_mode=0770,nounix,serverino,mapposix,rsize=61440,wsize=65536,actimeo=1)
//fs-mxp/ZZZshare/ASTE on /home/esales/aste type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=XXX,domain=YYY-it,uid=1001,forceuid,gid=1002,forcegid,addr=,file_mode=0770,dir_mode=0770,nounix,serverino,mapposix,rsize=61440,wsize=65536,actimeo=1)
//fs-mxp/ftp/YYYvendor on /home/esales/YYYvendor type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=XXX,domain=YYY-it,uid=1001,forceuid,gid=1002,forcegid,addr=,file_mode=0770,dir_mode=0770,nounix,serverino,mapposix,rsize=61440,wsize=65536,actimeo=1)
  • I would look at the log files (/var/log/samba/...) first and if they do not give enough detail, increase the verbosity to help diagnose, what's going on. The logs on the shared side may help too? Add the results to your original question, if you see something that might be useful. – X Tian May 23 '17 at 10:20
  • @X Tian: /var/log/samba/ is empty, any advice to turn on logging or increase verbosity? If I keep listing the folder every 5 seconds it does not drop... – neurino May 23 '17 at 10:38
  • @RuiFRibeiro: added mount output, thanks for your interest. – neurino Jun 5 '17 at 10:15
  • You might also want to consider using the automounter (autofs4), which will automatically and transparently mount and umount filesystems on demand. – roaima Jun 6 '17 at 11:05

I guess this has something related to patches delivered by windows updates to prevent ransom-ware attack. It seams the server which holds the shared folder rejects CIFS V1 requests. By default mount uses CIFS V1. give it a try by adding vers=2.0 to the end of your mount command. I had the same problem and this way i manged to fix it. PS / FYI : my command looks as follows

// /media/windowsshare cifs credentials=/home/MY_USERNAME/.smbcredentials,iocharset=utf8,sec=ntlm,vers=2.0 0 0

  • Thank you, I tried adding vers=2.0 at the end, let's see if it solves. In the meanwhile I added a cron job that every 5 minutes touches the shares to keep alive, I'm posting my workaround too for reference. – neurino May 26 '17 at 12:18
  • The syntax, while accepted, was wrong, and the connection were still done with 1.0; options should be done in the 4th field, and not at the end. I edited the code, and replace the tags with <code>, as it is more appropriate for showing a long line. – Rui F Ribeiro May 29 '17 at 14:44

From your mount output added to your question, we can see you are still using CIFS 1.0.

I would advise to mount the mount as CIFS 2.1 if the servers supports it, as that from CIFS v2.0 or 2.1 the protocol supports a better recovery from connection sleep/cuts. To do that the option is vers=2.1.

Durable handles (2.02, 2.1) – allow for connection to transparently reconnect to the server if there is a temporary disconnection

I also advise to add the option echo_interval=60 instead of adding a while loop, as in that way, the SMB client code sends itself a keepalive beacon every minute to the server.

Beware, that as I warned and corrected in @Thillina answer, the options are all on the 3rd field separated by a comma.

For more details, please see CIFS randomly losing connection to Windows share

Reading the articles I am quoting in my post:

3.0 - The SMBv3.0 protocol that was introduced in Microsoft Windows 8 and Windows Server 2012.

So you having Windows server 2012 means that ar least the Windows side supports CIFSv3.0 and lower.

To check if it was renegotiated and with which version, change the options in your fstab file, and do:

#mount -o remount /media/docs

and then run a mount command to check with what version the mount was done/negotiated.

  • Thanks Rui, I changed to suggested vers=2.1 -- BTW how do I check if the server supports it? It's a Win Server 2012 -- unluckily it won't mount with option echo_interval=60 so, at the moment, I'm leaving my cifs ping on – neurino Jun 5 '17 at 13:03
  • added to the answer. I suggest to read my own link/answer, as it is related and quite detailed; you original question is a bit confusing, I could swear it was a Samba Server + Linux client until now, and from the comments about looking at /var/log/samba, it seems I was not the only one. – Rui F Ribeiro Jun 5 '17 at 14:10
  • Thanks Rui, the mount is done now with version 3.0! Sorry for any confusion created, I can't get where it's blurred, if you need more info I will add them for reference. Still I had trouble with the echo_interval=60 option. – neurino Jun 5 '17 at 14:26
  • No problem at all, I was just providing feedback. – Rui F Ribeiro Jun 5 '17 at 14:31

I ended up with a cron job that every 3 minutes touches a file on each cifs share in mount to keep the connection alive.

So far shares are back to normal availability:



while read spot; do
   touch --no-create "${spot}/.cifs_keepalive"
done <<< "$(mount | awk '/cifs/{ print $3; }')"


*/3 *   *   *   *   root    /home/bcait/bca_util/bin/cifs_keepalive >/dev/null 2>&1

Credits: I got the idea from this blog post.


In my case, I had other network interfaces which were disconnected. DHCP lease expiries on those interfaces caused the mounts to drop According to http://ubuntuforums.org/showthread.php?t=1140094 Samba reloads.

For me I disabled those interfaces. Another possible solution could be autofs with 0 timeout.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.