96

I am a little confused on the proper fstab entry for a samba share in Ubuntu 12.04

  • I can get the drive to mount manually by using:

    sudo mount -t cifs //192.168.2.2/raid_drive /mnt/homeserver -o username=jon,password=password
    
  • So I tried putting this in fstab:

    //192.168.2.2/raid_drive /mnt/homeserver cifs username=jon,password=password,iocharset=utf8,mode=0777,dir_mode=07‌​77 0 0
    
  • Which gives me this error in syslog:

    kernel: [ 2217.925354] CIFS: Unknown mount option mode
    kernel: [ 2217.936345] CIFS VFS: default security mechanism requested.  The default security mechanism will be upgraded from ntlm to ntlmv2 in kernel release 3.3
    
  • This guide says to use smbfs although I believe smbfs is deprecated?

What is a common fstab configuration for a samba share in Ubuntu 12.04?

EDIT:

Using the accepted answer below I was initially getting this error message (from dmesg):

[   45.520883] CIFS VFS: Error connecting to socket. Aborting operation
[   45.520990] CIFS VFS: cifs_mount failed w/return code = -115

although it turns out this was due to network connectivity issues, and not related to improper fstab entry.

Jorge Castro
  • 73,907
jpetersen
  • 5,649
  • That means you'll have to pass the password on the file? Is that a way to make the password secure? –  Oct 16 '12 at 12:12
  • You could try using the server computer's IP address instead of its name. –  Sep 04 '12 at 14:59
  • 1
    You can use a .smb credentials file with only root permission as @russnash suggests below. – jpetersen Oct 16 '12 at 15:37
  • 1
    just tried your solution, but then i type sudo moun -a i get a error: [mntent]: line 13 in /etc/fstab is bad this is what i have typed /etc/fstab: //192.168.1.8/avcenter/Service\ -\ Installation /media/Service cifs credentials=.smbcredentials,uid=shareuser,gid=sharegroup 0 0 the reason for \ is that i read somewhere that if there where spaces in the folder then i should type \ to indicate that its a space.. even tried "Service - Installation" –  Mar 18 '13 at 21:08

2 Answers2

160

I've been through exactly this same issue this morning with 12.04 and here's how I got it working:

Install cifs-utils Install smbfs (even if you already have Samba and related packages installed):

sudo apt-get install cifs-utils

Edit /etc/fstab and add your entry:

//server/share /pathto/mountpoint cifs credentials=/home/username/.smbcredentials,uid=shareuser,gid=sharegroup 0 0

Create the .smbcredentials file in your home directory:

username=shareuser
password=sharepassword
domain=domain_or_workgroupname

Make sure you secure your ~/.smbcredentials file:

chmod 0600 ~/.smbcredentials

Finally, test the mount with:

sudo mount -a

...and you should be good to go!

russnash
  • 1,616
  • 1
  • 11
  • 2
  • 3
    I can't write to the share, even though the same user can when logging in with Windows. Is this a read only mount? – waspinator Dec 15 '12 at 05:55
  • 1
    smbfs has been replaced with cifs-utils, other than that the instructions work for me too. – metakermit Nov 08 '13 at 16:42
  • 4
    I ran into an error ("bad option: uid=my_username"). I got past it by removing the uid & gid options in fstab. – reg Oct 02 '14 at 06:14
  • 2
    @reg The correct option is user when the username is given (similarly group) since uid is for the numerical user id. – Premek Brada Nov 13 '14 at 20:18
  • 4
    As an aside, the Ubuntu wiki has a full page on mounting samba shares including troubleshooting stuff. – Premek Brada Nov 13 '14 at 20:20
  • //server/share /pathto/mountpoint cifs password= – Sergey Shuchkin Sep 10 '15 at 04:33
  • 5
    The reason why you should put your credentials into a file is because /etc/fstab is readable by everyone and so are your passwords in it. Source: https://wiki.ubuntu.com/MountWindowsSharesPermanently#Mount_password_protected_network_folders – ttt Jun 23 '17 at 08:51
  • "username=domain/user" in the credentials file worked fine for smbclient, but @russnash's idea here of splitting it out to a separate line finally fixed it for me. THANK YOU! – harvest316 Mar 08 '18 at 02:58
  • How does this work if I have a server with MULTIPLE shares? For example, I have a SMB location `smb://nas6aba8c.local/) that has hundreds of folders/shares, I want them all mounted, but I obviously can't list them all. – Raleigh L. Aug 11 '22 at 05:59
  • @RaleighL. you asked a while back so I assume you figured this out. No you can't do that, you obviously must list them all. Simple way is to use a script to update fstab, all values except the share name / mount point will stay the same. – ocodo May 14 '25 at 06:27
  • @PremekBrada - I'm not sure which version of cifs etc you're using but uid and gid are the options, you can supply the number or name, they're interchangeable. (user and group are not valid options for me when running the fstab/cifs line) – ocodo May 14 '25 at 06:29
5

Your initial problem is in the option mode, as syslog says in the first line. What you probably meant was file_mode, see man mount.cifs for more information.

The credential approach mentioned by Eliah is indeed better than using username and password, but I don't think it interferes with the other options like file_mode or dir_mode.

Eric Carvalho
  • 55,573
Vitor
  • 51